Home Segments Top Top Previous Next

178: Mainline

Instead of handing three integer arguments to movieRating, you can write a rating method that takes just one argument, which you declare to be a Movie instance. Of course, you need to change the body: instead of s, a, and d parameters, the body must refer to the Movie instance's script, acting, and direction instance variables:

public class Movie { 
 public int script, acting, direction; 
 public static int rating (Movie m) { 
  return m.script + m.acting + m.direction; 
 } 
} 

Because the method defined in this segment works only on those arguments that are movies, there is no need to call the method movieRating—the method cannot be called on any argument that is not a movie.