In Java This program introduces the concept of inheritance by creating subclasse
ID: 3847446 • Letter: I
Question
In Java
This program introduces the concept of inheritance by creating subclasses of a Movie class.
The program should have two classes: MoviesClass.java
MoviesMainClass.java
Create a class named MoviesClass.
TheMoviesClass class should track the Motion Picture Association of America (MPAA) rating (e.g., Rated G, PG-13, R, etc.), ID Number, and movie title with appropriate accessor and mutator methods.
Inside the MovieClass create an equals( ) method that overrides MovieClass equals ( ) method, such that two movies are equal if their ID number is identical.
Inside the MovieClass create three additional movie rating type classes named:
ActionMovie ComedyMovie DramaMovie
that are derived from Movie.
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 rating type.
Create a method called toString() that displays all the movie object values and states in a well formatted manner. The following are the late fees for movie rating types:
Default
$2.00/day
Action
$3.00/day
Comedies
$2.50/day
Dramas
$2.00/day.
Test your classes from a main method.
The main class must include driver code that tests all the objects paths. The driver code in the main class should not be prompted based.
Explanation / Answer
// MoviesClass.java
public class MoviesClass
{
private String movieRating;
private int IDnumber;
private String movieTitle;
public MoviesClass()
{
movieRating = "";
IDnumber = 0;
movieTitle = "";
}
public MoviesClass(String rating, int id, String title)
{
movieRating = rating;
IDnumber = id;
movieTitle = title;
}
public String getmovieRating()
{
return movieRating;
}
public void setmovieRating(String rating)
{
movieRating = rating;
}
public int getIDnumber()
{
return IDnumber;
}
public void setIDnumber(int id)
{
IDnumber = id;
}
public String getmovieTitle()
{
return movieTitle;
}
public void setmovieTitle(String title)
{
movieTitle = title;
}
public double calcLateFees(int days)
{
return 2.0 * days;
}
public boolean equals(Object movieobject)
{
if(movieobject == null)
return false;
else if(getClass() != movieobject.getClass())
return false;
else
{
MoviesClass other = (MoviesClass)movieobject;
return (movieRating.equals(other.movieRating) && IDnumber == other.IDnumber && movieTitle.equals(other.movieTitle));
}
}
public String toString()
{
return " MPAA Rating: " + movieRating + " ID Number: " + IDnumber+ " Movie Title: " + movieTitle;
}
}
// DramaMovie.java
public class DramaMovie extends MoviesClass
{
public DramaMovie()
{
super();
}
public DramaMovie(String rating, int id, String title)
{
super(rating, id, title);
}
public double calcLateFees(int days)
{
return 2.0 * days;
}
}
// ComedyMovie.java
public class ComedyMovie extends MoviesClass
{
public ComedyMovie()
{
super();
}
public ComedyMovie(String aRating, int aID, String aTitle)
{
super(aRating, aID, aTitle);
}
public double calcLateFees(int days)
{
return 2.5 * days;
}
}
// ActionMovie.java
public class ActionMovie extends MoviesClass
{
public ActionMovie()
{
super();
}
public ActionMovie(String aRating, int aID, String aTitle)
{
super(aRating, aID, aTitle);
}
public double calcLateFees(int days)
{
return 3.0 * days;
}
}
// MoviesMainClass.java
public class MoviesMainClass
{
public static void main(String[] args)
{
MoviesClass movie = new MoviesClass("PG-11", 3691, "Guardians of Galaxy");
System.out.println(movie);
System.out.println("Late Fee: $" + movie.calcLateFees(6));
ActionMovie action = new ActionMovie("A", 2587, "Dejavu");
System.out.println(action);
System.out.println("Late Fee: $" + action.calcLateFees(6));
ComedyMovie comedy = new ComedyMovie("C", 7989, "Despicable me");
System.out.println(comedy);
System.out.println("Late Fee: $" + comedy.calcLateFees(6));
DramaMovie drama = new DramaMovie("PG-12", 4563, "Honey I shrunk");
System.out.println(drama);
System.out.println("Late Fee: $" + drama.calcLateFees(6));
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.