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

IN JAVA LANGUAGE USING ECLIPSE OR NETBEANS PLEASE: Create a class named Movie th

ID: 3815806 • Letter: I

Question

IN JAVA LANGUAGE USING ECLIPSE OR NETBEANS PLEASE:

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.

You will create four java files – Movie.java, Action.java, Comedy.java, and Drama.java. Here, Action, Comedy, and Drama classes are derived from Movie class.

Create another class called Rental (Rental.java). This class should store a Movie that is rented, an integer representing the ID of the customer that rented the movie, and an integer indicating how many days late the movie is. Add a method that calculates the late fees for rental.

In the main method, create an array (choose size of at least 10) that can hold objects of Rental class. Fill the array with objects of Rental class. Make sure the rental objects in the array are from different types of movies (Action, Comedy, Drama). Also make some of the rental objects in the array to be late. Now iterate through the array to calculate the following:

Number of rental objects that belong to Action movie type.

Number of rental objects that belong to Drama movie type.

Number of rental objects that belong to Comedy movie type.

Number of rental objects, which are late.

Total amount of late fees.

Explanation / Answer

Assuming we need to calculate all these for all the customers not for each customer, Here is my code below: -

1. Movie.java

package movie;

public class Movie {
   private String MPAArating;
   private Integer idNum;
   private String movieTitle;
   public String getMPAArating() {
       return MPAArating;
   }
   public void setMPAArating(String mPAArating) {
       MPAArating = mPAArating;
   }
   public Integer getIdNum() {
       return idNum;
   }
   public void setIdNum(Integer idNum) {
       this.idNum = idNum;
   }
   public String getMovieTitle() {
       return movieTitle;
   }
   public void setMovieTitle(String movieTitle) {
       this.movieTitle = movieTitle;
   }
   @Override
   public boolean equals(Object obj) {
       // TODO Auto-generated method stub
       if (obj == null) {
   return false;
   }
   if (!Movie.class.isAssignableFrom(obj.getClass())) {
   return false;
   }
   final Movie other = (Movie) obj;
  
   if (this.idNum != other.idNum) {
   return false;
   }
   return true;
   }
   public Double calcLateFees(int n) {
       return n*2.0;
   }
  
  
}

2. Action.java

package movie;

public class Action extends Movie {
  
   public Double calcLateFees(int n) {
       return n*3.0;
   }
}

3. Drama.java

package movie;

public class Drama extends Movie {
   public Double calcLateFees(int n) {
       return n*2.0;
   }
}

3. Comedy.java

package movie;

public class Comedy extends Movie {

   public Double calcLateFees(int n) {
       return n*2.50;
   }
}

4. Rental.java

package movie;

public class Rental {
   private Movie movie;
   private Integer numOfLateDays;
   private Integer customerId;
  
  
   public Movie getMovie() {
       return movie;
   }


   public void setMovie(Movie movie) {
       this.movie = movie;
   }


   public Integer getNumOfLateDays() {
       return numOfLateDays;
   }


   public void setNumOfLateDays(Integer numOfLateDays) {
       this.numOfLateDays = numOfLateDays;
   }


   public Integer getCustomerId() {
       return customerId;
   }


   public void setCustomerId(Integer customerId) {
       this.customerId = customerId;
   }


   public Double calculateLateFees() {
       return this.movie.calcLateFees(this.numOfLateDays);
   }
  
}

5. MainDriver.java

package movie;

public class MainDriver {
   public static void main(String[] args) {
       Rental rentedMovs[] = new Rental[10];
       int count = 0;
       Rental r;
       Movie m;
       r = new Rental();
       m = new Action();
       m.setIdNum(1);
       m.setMovieTitle("Prison Escape");
       m.setMPAArating("Rated G");
       r.setCustomerId(1);
       r.setMovie(m);
       r.setNumOfLateDays(2);
       rentedMovs[count++]=r;
      
      
       r = new Rental();
       m = new Action();
       m.setIdNum(2);
       m.setMovieTitle("Fight Club");
       m.setMPAArating("Rated G");
       r.setCustomerId(1);
       r.setMovie(m);
       r.setNumOfLateDays(0);
       rentedMovs[count++]=r;
      
       r = new Rental();
       m = new Action();
       m.setIdNum(3);
       m.setMovieTitle("Blood Bath");
       m.setMPAArating("R");
       r.setCustomerId(2);
       r.setMovie(m);
       r.setNumOfLateDays(4);
       rentedMovs[count++]=r;
      
       r = new Rental();
       m = new Comedy();
       m.setIdNum(4);
       m.setMovieTitle("Humpty Dumpty");
       m.setMPAArating("R");
       r.setCustomerId(2);
       r.setMovie(m);
       r.setNumOfLateDays(2);
       rentedMovs[count++]=r;
      
       r = new Rental();
       m = new Comedy();
       m.setIdNum(5);
       m.setMovieTitle("Kung Fu panda");
       m.setMPAArating("PG-13");
       r.setCustomerId(1);
       r.setMovie(m);
       r.setNumOfLateDays(6);
       rentedMovs[count++]=r;
      
       r = new Rental();
       m = new Drama();
       m.setIdNum(6);
       m.setMovieTitle("Love Story");
       m.setMPAArating("R");
       r.setCustomerId(2);
       r.setMovie(m);
       r.setNumOfLateDays(1);
       rentedMovs[count++]=r;
      
       r = new Rental();
       m = new Drama();
       m.setIdNum(7);
       m.setMovieTitle("Life's True");
       m.setMPAArating("PG-13");
       r.setCustomerId(1);
       r.setMovie(m);
       r.setNumOfLateDays(8);
       rentedMovs[count++]=r;
      
       r = new Rental();
       m = new Drama();
       m.setIdNum(8);
       m.setMovieTitle("NO ITs True");
       m.setMPAArating("R");
       r.setCustomerId(2);
       r.setMovie(m);
       r.setNumOfLateDays(0);
       rentedMovs[count++]=r;
      
       r = new Rental();
       m = new Drama();
       m.setIdNum(9);
       m.setMovieTitle("Its Beautiful");
       m.setMPAArating("PG-13");
       r.setCustomerId(1);
       r.setMovie(m);
       r.setNumOfLateDays(0);
       rentedMovs[count++]=r;
      
       r = new Rental();
       m = new Action();
       m.setIdNum(10);
       m.setMovieTitle("Bang On!");
       m.setMPAArating("PG-13");
       r.setCustomerId(2);
       r.setMovie(m);
       r.setNumOfLateDays(2);
       rentedMovs[count++]=r;
      
       int countAction = 0,countComedy = 0,countDrama = 0,countLateRentals = 0;
       double totalLateFees = 0.0;
      
       Rental iterR;
       for(int i = 0;i<rentedMovs.length;i++) {
           iterR = rentedMovs[i];
           if (iterR.getMovie() instanceof Action){ // checking which type of movie is this
               countAction++;
           }
           if (iterR.getMovie() instanceof Comedy){
               countComedy++;
           }
           if (iterR.getMovie() instanceof Drama){
               countDrama++;
           }
           if(iterR.getNumOfLateDays() > 0) {// If the movie is late calculate late fees
               countLateRentals++;
               totalLateFees = totalLateFees + iterR.calculateLateFees();
           }
       }
      
       System.out.println("Number of rental objects that belong to Action movie type:"+countAction);
       System.out.println("Number of rental objects that belong to Drama movie type:"+countDrama);
       System.out.println("Number of rental objects that belong to Comedy movie type:"+countComedy);
       System.out.println("Number of rental objects, which are late:"+countLateRentals);
       System.out.println("Total amount of late fees: $"+totalLateFees);
      
   }
}

If you want to calculate for each customer then in the code where we are iterating, add if block for customerId and print the results accordingly.