Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

– Movie Problem (Java language) Consider a movie rental business. Create a class

ID: 3588815 • Letter: #

Question

– Movie Problem (Java language)

Consider a movie rental business. Create a class named Movie which can be used for your video rental business. The Movie class should track the following: Motion Picture Association of America Rating (e.g. Rated G, PG-13, R) ID number Movie title. Ensure appropriate getter/setter methods in your class definition. Create an equals() method (which overrides java.lang.Object’s method), where two movies objects are equal if their ID number is identical.

Next, create three additional classes named Action, Comedy and Drama which are each derived from Movie. Lastly create an overridden method named calculateLateFees which takes input a number of days the movie is late and returns the late fee for that movie. The default fee is $2 a day. Action movies have a fee of $3 per day, comedies are $2.50 per day, and dramas are $2 per day.

Test your classes with a main method, either inside one of the classes or inside a class of its own.

Save your submission in Movie.java, Action.java, Comedy.java, and Drama.java.

Explanation / Answer

PROGRAM CODE:

package util;

public class Movie {

   private String MPAARating;

   private int ID;

   private String movieTitle;

  

   Movie(String title, int id, String rating )

   {

       movieTitle = title;

       ID = id;

       MPAARating = rating;

   }

   public String getMPAARating() {

       return MPAARating;

   }

   public void setMPAARating(String mPAARating) {

       MPAARating = mPAARating;

   }

   public int getID() {

       return ID;

   }

   public void setID(int iD) {

       ID = iD;

   }

   public String getMovieTitle() {

       return movieTitle;

   }

   public void setMovieTitle(String movieTitle) {

       this.movieTitle = movieTitle;

   }

  

   @Override

   public boolean equals(Object obj) {

       Movie m = (Movie)obj;

       return m.ID == this.ID;

   }

  

   public double calcLateFees(int numDays)

   {

       return 2*numDays;

   }

  

  

}

public class Comedy extends Movie

{

   Comedy(String title, int id, String rating) {

       super(title, id, rating);

       // TODO Auto-generated constructor stub

   }

   @Override

   public double calcLateFees(int numDays) {

       // TODO Auto-generated method stub

       return 2.5 * numDays;

   }

}

public class Drama extends Movie

{

   Drama(String title, int id, String rating) {

       super(title, id, rating);

       // TODO Auto-generated constructor stub

   }

}

public class Action extends Movie

{

   Action(String title, int id, String rating) {

       super(title, id, rating);

       // TODO Auto-generated constructor stub

   }

   @Override

   public double calcLateFees(int numDays) {

       // TODO Auto-generated method stub

       return 3*numDays;

   }

}

public class Tester

{

public static void main(String args[])

{

   Movie drama = new Drama("The Notebook", 367644, "R");

   System.out.println(drama.calcLateFees(5));

   Movie action = new Action("Knight and Day", 24762, "PG-13");

   System.out.println(action.calcLateFees(2));

   Movie comedy = new Comedy("Liar Liar", 26843, "G");

   System.out.println(comedy.calcLateFees(5));

}

}

OUTPUT:

10.0

6.0

12.5