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

Create a class named Movie that can be used with your video rental business. The

ID: 3536124 • 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 overriden 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.

In Addition to the requirements listed in the book PLEASE INCLUDE THE FOLLOWING!

- ALL APPROPRIATE ACCESSOR AND MUTATOR METHODS (GETTERS AND SETTERS)

- AN EQUALS METHOD

- A 'TO STRING METHOD'

-AT LEAST 2 CONSTRUCTORS (DEFAULT AND OVERLOADED)

-A 'COPY' CONSTRUCTOR

- A 'CLONE' METHOD

- A 'FINALIZE' METHOD, AND

- A 'DISPOSE' METHOD

Explanation / Answer

public class ActionMovie extends Movie

{

// Constants

private static final double LATE_FEE_ACTION = 3;


// Constructor

public ActionMovie(Integer subID, String subTitle, String subRating)

{

super(subID, subTitle, subRating);

}


// Method for computing the late fee

public void calcLateFee(double daysLate)

{

lateFeeTotal = LATE_FEE_ACTION * daysLate;

}

}


public class ComedyMovie extends Movie

{

// Constants

private static final double LATE_FEE_COMEDY = 2.5;


// Constructor

public ComedyMovie(Integer subID, String subTitle, String subRating)

{

super(subID, subTitle, subRating);

}


// Method for computing the late fee

public void calcLateFee(double daysLate)

{

lateFeeTotal = LATE_FEE_COMEDY * daysLate;

}

}


public class DramaMovie extends Movie

{

// Constants

private static final double LATE_FEE_DRAMA = 2;


// Constructor

public DramaMovie(Integer subID, String subTitle, String subRating)

{

super(subID, subTitle, subRating);

}


// Method for computing the late fee

public void calcLateFee(double daysLate)

{

lateFeeTotal = LATE_FEE_DRAMA * daysLate;

}

}


public class Movie

{

// Movie Variables

private Integer idNumber;

private String movieTitle;

private String mpaaRating;


// Variables that determine fee

private int daysLate;

double lateFeeTotal;


// Constants

private static final double LATE_FEE_DEFAULT = 2;


// Constructor

public Movie(int movID, String movTitle, String movRating)

{

this.idNumber = movID;

this.movieTitle = movTitle;

this.mpaaRating = movRating;

}


// Methods for ID

public Integer getIdNumber() //Accessor

{

return idNumber;

}


public void setIdNumber(int movID) //Mutator

{

if (movID >= 0)

idNumber = movID;

else

{

System.out.println("Error: Negative ID");

System.exit(0);

}

}


// Methods for Title

public String getMovieTitle() //Accessor

{

return movieTitle;

}


public void setMovieTitle(String movTitle) //Mutator

{

if (movTitle.equals("") || movTitle.equals(" "))

{

System.out.println("Error: Empty Title");

System.exit(0);

}

else

movieTitle = movTitle;

}


// Methods for Rating

public String getMpaaRating() //Accessor

{

return mpaaRating;

}


public void setMpaaRating(String movRating) //Mutator

{

if (movRating.equals("") || movRating.equals(" "))

{

System.out.println("Error: Empty Rating");

System.exit(0);

}

else

mpaaRating = movRating;

}


// Equals Method

public boolean equals(Movie objectName)

{

return objectName.getIdNumber() == idNumber;

}


// To String Method

public String toString()

{

String numID = Integer.toString(idNumber);

return (numID);

}


// Methods for the late fee

public double getLateFee() //Accessor

{

return lateFeeTotal;

}


public void calcLateFee(double daysLate)

{

lateFeeTotal = LATE_FEE_DEFAULT * daysLate;

}

}


public class MovieDemo

{

public static void main(String[] args)

{

System.out.println("Demonstration Started:");

System.out.println();


// Constructor

ActionMovie mov1 = new ActionMovie(1, "Rush Hour", "PG-13");

ComedyMovie mov2 = new ComedyMovie(2, "The Hangover", "R");

DramaMovie mov3 = new DramaMovie(3, "Titanic", "PG-13");


// Check ID Mutator

System.out.println("Check ID Mutator:");

System.out.println("Original ID: " + mov1.getIdNumber());

mov1.setIdNumber(2);

System.out.println("Modified ID: " + mov1.getIdNumber());

System.out.println();


// Check Equals Method

System.out.println("Check Equals Method:");

Integer v1, v2;

v1 = mov1.getIdNumber();

v2 = mov2.getIdNumber();

System.out.println(mov1.getIdNumber() + " equals " + mov2.getIdNumber() +

"? " + v1.equals(v2));

System.out.println();

mov1.setIdNumber(1); //Change it back

System.out.println("Check Equals Method:");

v1 = mov1.getIdNumber();

v2 = mov2.getIdNumber();

System.out.println(mov1.getIdNumber() + " equals " + mov2.getIdNumber() +

"? " + v1.equals(v2));

System.out.println();


// Check Title Mutator

System.out.println("Check Title Mutator:");

System.out.println("Original Title: " + mov3.getMovieTitle());

mov3.setMovieTitle("The Aviator");

System.out.println("Modified Title: " + mov3.getMovieTitle());

System.out.println();


// Check Rating Mutator

System.out.println("Check Rating Mutator:");

System.out.println("Original Rating: " + mov2.getMpaaRating());

mov2.setMpaaRating("G");

System.out.println("Modified Rating: " + mov2.getMpaaRating());

System.out.println();


// Calculate Late Charges

System.out.println("Calculate Late Charge:");


mov1.calcLateFee(3);

System.out.print("The movie with ID #" + mov1.getIdNumber() +

" has a late charge of $");

System.out.printf("%6.2f", mov1.getLateFee());

System.out.println(" !");


mov2.calcLateFee(5);

System.out.print("The movie with ID #" + mov2.getIdNumber() +

" has a late charge of $");

System.out.printf("%6.2f", mov2.getLateFee());

System.out.println(" !");


mov3.calcLateFee(7);

System.out.print("The movie with ID #" + mov3.getIdNumber() +

" has a late charge of $");

System.out.printf("%6.2f", mov3.getLateFee());

System.out.println(" !");

}

}


Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote