A fourth virtue of procedure abstraction is that you can
augment repetitive
computationseasily. For example, in Segment 114, you have seen
the movieRating
method defined as follows:
public class Movie { // Define movieRating: public static int movieRating (int s, int a, int d) { return s + a + d; } }
You can easily add a line that displays the rating every time that the rating is computed:
public class Movie {
// Define movieRating:
public static int movieRating (int s, int a, int d) {
System.out.print("The rating of the movie is " + (s + a + d));
return s + a + d;
}
}
Thus, you do not need to bother to find all the places where a rating is
computed, because you need to change only the movieRating
method's
definition.