By way of summary, the following are complete
definitions of the Attraction
, Movie
, and Symphony
classes that
serve from here through Chapter 37.
They include all that has
been developed so far, plus two additional instance variables, title
and poster
, which are used in Chapter 31:
public abstract class Attraction { // First, define instance variables: public int minutes; public String title, poster; // Define constructors: public Attraction () {minutes = 75;} public Attraction (int m) {minutes = m;} // Define getters and setters: public int getMinutes () {return minutes;} public void setMinutes (int m) {minutes = m;} // Define rating as an abstract method: public abstract int rating () ; // Define category as an abstract method: public abstract String category () ; // Define describe: public void describe () { System.out.println( category() + " with rating " + rating() + " lasts " + getMinutes() + " minutes" ); } }
public class Movie extends Attraction { // First, define instance variables: public int script, acting, direction; // Define zero-parameter constructor: public Movie () {script = 5; acting = 5; direction = 5;} // Define one-parameter constructor: public Movie (int m) {super(m);} // Define three-parameter constructor: public Movie (int s, int a, int d) { script = s; acting = a; direction = d; } // Define four-parameter constructor: public Movie (int s, int a, int d, int m) { this(s, a, d); minutes = m; } // Define rating: public int rating () {return script + acting + direction;} // Define category: public String category () {return "Movie";} }
public class Symphony extends Attraction { // First, define instance variables: public int music, playing, conducting; // Define zero-parameter constructor: public Symphony () {music = 5; playing = 5; conducting = 5;} // Define one-parameter constructor: public Symphony (int m) {super(m);} // Define three-parameter constructor: public Symphony (int s, int a, int d) { music = s; playing = a; conducting = d; } // Define four-parameter constructor: public Symphony (int s, int a, int d, int m) { this(s, a, d); minutes = m; } // Define rating: public int rating () {return music + playing + conducting;} // Define category: public String category () {return "Symphony";} }