Using Java
Create a class named Movie that can be used in 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. To demonstrate polymorphism:
Test your program using several different objects derived from the Movie class – at least one of each derived type -- to ensure that everything works properly.
Code - Main.java
class Movie
{
private String movieRating;
private int movieID;
private String movieTitle;
public Movie()
{
movieRating = "";
movieID = 0;
movieTitle = "";
}
public Movie(String movRating, int movID, String
movTitle)
{
movieRating = movRating;
movieID = movID;
movieTitle = movTitle;
}
public String getMovieRating()
{
return movieRating;
}
public void setMovieRating(String movRating)
{
movieRating = movRating;
}
public int getMovieID()
{
return movieID;
}
public void setMovieID(int movID)
{
movieID = movID;
}
public String getMovieTitile()
{
return movieTitle;
}
public void setMovieTitile(String movTitle)
{
movieTitle = movTitle;
}
public double calcMovieFees(int days)
{
return 2.0 * days;
}
public boolean equals(Object movObj)
{
if(movObj == null)
return
false;
else if(getClass() !=
movObj.getClass())
return
false;
else
{
Movie other =
(Movie)movObj;
return
(movieRating.equals(other.movieRating) && movieID ==
other.movieID
&&
movieTitle.equals(other.movieTitle));
}
}
public String toString()
{
return "\nMPAA Rating: " +
movieRating + "\nID Number: " + movieID
+ "\nMovie Title: " + movieTitle;
}
}
// Action.java
class Action extends Movie
{
public Action()
{
super();
}
public Action(String movRating, int movID, String
movTitle)
{
super(movRating, movID,
movTitle);
}
public double calcMovieFees(int days)
{
return 3.0 * days;
}
}
// Comedy.java
class Comedy extends Movie
{
public Comedy()
{
super();
}
public Comedy(String movRating, int movID, String
movTitle)
{
super(movRating, movID,
movTitle);
}
public double calcMovieFees(int days)
{
return 2.5 * days;
}
}
// Drama.java
class Drama extends Movie
{
public Drama()
{
super();
}
public Drama(String movRating, int movID, String
movTitle)
{
super(movRating, movID,
movTitle);
}
public double calcMovieFees(int days)
{
return 2.0 * days;
}
}
// MovieTest.java
public class Main
{
public static void main(String[] args)
{
Movie movie = new Movie("PG-13",
6589, "Baby Day Out");
Action actionMovie = new
Action("G", 5946, "Mission Impossible");
Comedy comedyMovie = new
Comedy("R", 3584, "Dictator");
Drama dramaMovie = new
Drama("PG-13", 4865, "Avengers");
System.out.println(movie);
System.out.println("Late Fee: $" +
movie.calcMovieFees(6));
System.out.println(actionMovie);
System.out
.println("Late Fee: $" +
actionMovie.calcMovieFees(6));
System.out.println(comedyMovie);
System.out
.println("Late Fee: $" +
comedyMovie.calcMovieFees(6));
System.out.println(dramaMovie);
System.out.println("Late Fee: $" +
dramaMovie.calcMovieFees(6));
}
}
Screenshots -
pls do give a like , thank you
Get Answers For Free
Most questions answered within 1 hours.