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

----- JAVA Assignment ------ Create a class named Movie that can be used with yo

ID: 3778811 • Letter: #

Question

----- JAVA Assignment ------

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 and equals() method that overrides Object's equals() method, where two movies are equal if their ID number is identical.

Next, create three additional movie 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.


In Addition to the project create and add:
All appropriate accessor and mutator methods(Getters and setters)
an "equals ' method
a toString method
a default(noargument) constructor
and Overloaded constructor
a copy constructor
a clone method
a finalize method
a dispose method

Explanation / Answer

1. Movie.java

public class Movie implements Cloneable {
   int idNumber;
   String title;
   String rating;

   public Movie() {// defaul constructor
       super();
   }

   // overloaded constructor
   public Movie(int idNumber, String title, String rating) {
       super();
       this.idNumber = idNumber;
       this.title = title;
       this.rating = rating;
   }

   // copy onstructor
   public Movie(Movie s) {
       this.idNumber = s.idNumber;
       this.title = s.title;
       this.rating = s.rating;
   }

   public double calcLateFees(int noOfDelaysInDays) {
       return 2 * noOfDelaysInDays;
   }

   public int getIdNumber() {
       return idNumber;
   }

   public void setIdNumber(int idNumber) {
       this.idNumber = idNumber;
   }

   public String getTitle() {
       return title;
   }

   public void setTitle(String title) {
       this.title = title;
   }

   public String getRating() {
       return rating;
   }

   public void setRating(String rating) {
       this.rating = rating;
   }

   @Override
   public int hashCode() {
       final int prime = 31;
       int result = 1;
       result = prime * result + idNumber;
       return result;
   }

   @Override
   public boolean equals(Object obj) {
       if (this == obj)
           return true;
       if (obj == null)
           return false;
       if (getClass() != obj.getClass())
           return false;
       Movie other = (Movie) obj;
       if (idNumber != other.idNumber)
           return false;
       return true;
   }

   @Override
   public String toString() {
       return "Movie [idNumber=" + idNumber + ", title=" + title + ", rating="
               + rating + "]";
   }

   // method clone
   public Movie clone() throws CloneNotSupportedException {
       return (Movie) super.clone();
   }

   // method finalize
   protected void finalize() throws Throwable {
       super.finalize();
   }
}

-----------------------------------------

2. Action.java

public class Action extends Movie {
   public Action() {
       super();
   }

   public Action(int idNumber, String title, String rating) {
       super(idNumber, title, rating);
   }

   public Action(Movie s) {
       super(s);
   }

   // overridden calcLateFees
   @Override
   public double calcLateFees(int noOfDelaysInDays) {
       return 3 * noOfDelaysInDays;
   }
}


-----------------------------------------------

3. Comedy.java

public class Comedy extends Movie {
   public Comedy() {
       super();
   }

   public Comedy(int idNumber, String title, String rating) {
       super(idNumber, title, rating);
   }

   public Comedy(Movie s) {
       super(s);
   }

   // overridden calcLateFees
   @Override
   public double calcLateFees(int noOfDelaysInDays) {
       return 2.50 * noOfDelaysInDays;
   }
}

-------------------------------------------------------------

4. Drama.java

public class Drama extends Movie {
   public Drama() {
       super();
   }

   public Drama(int idNumber, String title, String rating) {
       super(idNumber, title, rating);
   }

   public Drama(Movie s) {
       super(s);
   }

   // overridden calcLateFees
   @Override
   public double calcLateFees(int noOfDelaysInDays) {
       return 2 * noOfDelaysInDays;
   }
}

------------------------------------------------------------------
5. TesterClass.java
public class TesterClass {

   public static void main(String args[]) throws Throwable {
       Movie action1 = new Action(1, "Movie1", "PG-13");
       System.out.println("Calculated Fees: " + action1.calcLateFees(5));
       System.out.println("Action1 : " + action1.toString());

       Movie action2 = action1.clone();
       System.out.println("cloned action2 : " + action2.toString());

       System.out.println("action1 is equals to action2 : "
               + action1.equals(action2));

       Movie comedy1 = new Comedy();
       System.out.println(" Calculated Fees: " + comedy1.calcLateFees(5));
       System.out.println("Comedy1 : " + comedy1.toString());

       Movie drama1 = new Drama();
       System.out.println(" Calculated Fees: " + drama1.calcLateFees(5));
       System.out.println("Drama1 : " + drama1.toString());
      
       drama1.finalize();
   }
}