Create a class named Movie that can be used with your video rental business. The
ID: 3837742 • Letter: C
Question
Create a class named Movie that can be used with your video rental business. The Movie class should track the Motion Picture Association of America (MPAA) rating (e.g., Rated G, PG-13. R), ID Number, and movie title with appropriate accessor and mutator methods. Also create an equals () method that overrides Object's equals () method, where two movies are equal if their ID number is identical. Next, create three additional classes named Action, Comedy, and Drama that are derived from Movie. Finally, create an overridden method named calcLateFees that takes as input the number of days a movie is late and returns the late fee for that movie. The default late fee is $2/day. Action movies have a late fee of $3/day, comedies are $2.50/day, and dramas are $2/day. Test your classes from a main method.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
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.