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

IN JAVA PLEASE. Create a class named Movie that can be used with your video rent

ID: 3816148 • Letter: I

Question

IN JAVA 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

//Movie.java

public class Movie {

   //Attributes of Movie
   String rating,ID,title;

   //Setters and Getters
   public String getRating() {
       return rating;
   }

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

   public String getID() {
       return ID;
   }

   public void setID(String iD) {
       ID = iD;
   }

   public String getTitle() {
       return title;
   }

   public void setTitle(String title) {
       this.title = title;
   }
  
   //Compares one object with other movie
   public boolean equals(Movie m){
       if(this.getID().equals(m.getID()))
           return true;
       else
           return false;
   }
}

//Action.java

public class Action extends Movie{

}

//Drama.java

public class Drama extends Movie{

}

//Comedy.java

public class Comedy extends Movie{

}

//Rental.java

import java.util.Scanner;

public class Rental {

   //Attributes of Rental
   Movie movie;
   int ID;
   int late;

   //Setters and Getters
   public Movie getMovie() {
       return movie;
   }
   public void setMovie(Movie movie) {
       this.movie = movie;
   }
   public int getID() {
       return ID;
   }
   public void setID(int iD) {
       ID = iD;
   }
   public int getLate() {
       return late;
   }
   public void setLate(int late) {
       this.late = late;
   }
  
   //Calculating late fees for each instance
   public double lateFees(Movie m,int late){
       if(m instanceof Action){ //Checking instanceof of type
           return late*3; //for action movies
       }else if(m instanceof Drama){
           return late*2; //for drama movies
       }else if(m instanceof Comedy){
           return late*2.50; //for comedy movies
       }else{
           return late*2; //other movies
       }
   }
  
   //main method
   public static void main(String args[]){
       //Rental 10 Objects
       Rental rental[] = new Rental[10];
       //Scanner object
       Scanner s = new Scanner(System.in);
       System.out.println("Enter the details of movie:");
      
       //Reading each rental object
       for(int i=0;i<rental.length;i++){
           rental[i] = new Rental();
           System.out.println("Enter Movie type:Action/Comedy/Drama:");
           //Reading Movie Name
           String mv = s.next();
           //Checking instanceof each object
           if(mv.equalsIgnoreCase("Action")){
               Action a = new Action();
               //Reading MovieID,title,Rating
               System.out.println("Enter Movie ID:");
               a.setID(s.next());
               System.out.println("Enter Movie Title:");
               a.setTitle(s.next());
               System.out.println("Enter Movie Rating:");
               a.setRating(s.next());
               //Adding Movie to array
               rental[i].setMovie(a);
           }else if(mv.equalsIgnoreCase("Drama")){
               Drama d = new Drama();
               System.out.println("Enter Movie ID:");
               d.setID(s.next());
               System.out.println("Enter Movie Title:");
               d.setTitle(s.next());
               System.out.println("Enter Movie Rating:");
               d.setRating(s.next());
               rental[i].setMovie(d);
           }else{
               Comedy c = new Comedy();
               System.out.println("Enter Movie ID:");
               c.setID(s.next());
               System.out.println("Enter Movie Title:");
               c.setTitle(s.next());
               System.out.println("Enter Movie Rating:");
               c.setRating(s.next());
               rental[i].setMovie(c);
           }
           System.out.println("Enter Customer ID:");
           rental[i].setID(s.nextInt());
           System.out.println("Enter no of late days:");
           rental[i].setLate(s.nextInt());
       }
      
       System.out.println("************************");
       int a=0,d=0,c=0;
       int lateObjects=0;
       double lateFee=0.0;
       //Iterating movies for calculating
       for(int i=0;i<rental.length;i++){
           if(rental[i].getMovie() instanceof Action){
               //Calculating Late Rental Objects
               if(rental[i].getLate()>0){
                   lateObjects++;
               }
               //Calculating Late Fees Objects
               double lf = rental[i].lateFees(rental[i].getMovie(),rental[i].getLate());
               lateFee = lateFee+lf;
               //Calculating count of each rental objects
               a++;
           }else if(rental[i].getMovie() instanceof Drama){
               if(rental[i].getLate()>0){
                   lateObjects++;
               }
               double lf = rental[i].lateFees(rental[i].getMovie(),rental[i].getLate());
               lateFee = lateFee+lf;
               d++;
           }else{
               if(rental[i].getLate()>0){
                   lateObjects++;
               }
               double lf = rental[i].lateFees(rental[i].getMovie(),rental[i].getLate());
               lateFee = lateFee+lf;
               c++;
           }
       }
      
       System.out.println("Number of Action Rental objects:"+a);
       System.out.println("Number of Drama Rental objects:"+d);
       System.out.println("Number of Comedy Rental objects:"+c);
       System.out.println("Number of Late Rental Objects:"+lateObjects);
       System.out.println("Total amount of Late Fees:$"+lateFee);
   }
}


Output:

Enter the details of movie:
Enter Movie type:Action/Comedy/Drama:
Action
Enter Movie ID:
A1
Enter Movie Title:
AM1
Enter Movie Rating:
G
Enter Customer ID:
101
Enter no of late days:
2
Enter Movie type:Action/Comedy/Drama:
Comedy
Enter Movie ID:
C1
Enter Movie Title:
CM1
Enter Movie Rating:
PG
Enter Customer ID:
102
Enter no of late days:
1
Enter Movie type:Action/Comedy/Drama:
Drama
Enter Movie ID:
D1
Enter Movie Title:
DM1
Enter Movie Rating:
R
Enter Customer ID:
103
Enter no of late days:
2
Enter Movie type:Action/Comedy/Drama:
Action
Enter Movie ID:
A2
Enter Movie Title:
Am2
Enter Movie Rating:
R
Enter Customer ID:
104
Enter no of late days:
2
Enter Movie type:Action/Comedy/Drama:
Comedy
Enter Movie ID:
C2
Enter Movie Title:
CM2
Enter Movie Rating:
G
Enter Customer ID:
105
Enter no of late days:
3
Enter Movie type:Action/Comedy/Drama:
Drama
Enter Movie ID:
D2
Enter Movie Title:
DM2
Enter Movie Rating:
R
Enter Customer ID:
106
Enter no of late days:
4
Enter Movie type:Action/Comedy/Drama:
Action
Enter Movie ID:
A3
Enter Movie Title:
AM3
Enter Movie Rating:
PG
Enter Customer ID:
107
Enter no of late days:
5
Enter Movie type:Action/Comedy/Drama:
Comedy
Enter Movie ID:
C3
Enter Movie Title:
CM3
Enter Movie Rating:
R
Enter Customer ID:
108
Enter no of late days:
1
Enter Movie type:Action/Comedy/Drama:
Drama
Enter Movie ID:
D3
Enter Movie Title:
DM3
Enter Movie Rating:
G
Enter Customer ID:
109
Enter no of late days:
2
Enter Movie type:Action/Comedy/Drama:
Action
Enter Movie ID:
A4
Enter Movie Title:
AM4
Enter Movie Rating:
PG
Enter Customer ID:
110
Enter no of late days:
2
************************
Number of Action Rental objects:4
Number of Drama Rental objects:3
Number of Comedy Rental objects:3
Number of Late Rental Objects:10
Total amount of Late Fees:$61.5