Question: In JAVA. I need help with my code. I seem to be having problems with my MAIN.JAVA and last part of my RENTAL.JAVA code. Here
In JAVA.
I need help with my code. I seem to be having problems with my MAIN.JAVA and last part of my RENTAL.JAVA code. Here is the problem:
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 Objects 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.
---------------------------------------------------------------
HERE IS MY CODE:
************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 { }
************COMEDY.JAVA************
public class Comedy extends Movie { }
************DRAMA.JAVA************
public class Drama 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.JAVA************
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[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 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); } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
