Home Segments Top Top Previous Next

148: Mainline

Suppose that you want to adjust your way of calculating movie ratings by introducing weights. You could insert those weights into the movie-rating method directly:

public class Movie { 
 // Define movieRating: 
 public static int movieRating (int s, int a, int d) { 
  return 6 * s + 13 * a + 11 * d; 
 } 
} 

Such direct insertion is not a good idea, however. Sprinkling numbers throughout a program creates problems, as a program grows, because you easily can forget where such numbers are located.

A safer approach is to use variables. You cannot use local variables, however, because local variables exist only during the execution of their corresponding blocks.