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

here are the requirements: The Rental class The Rental class is an abstract clas

ID: 3639660 • Letter: H

Question

here are the requirements:
The Rental class

The Rental class is an abstract class which implements Comparable<Rental> and Comparator<Rental>.

The class represents a Rentable object and it is going to be the superclass for the Movie and Videogame classes.

NOTE: Remember to import java.util.Comparator for this class

Properties:
----------
1) protected String title.
2) protected String genre.
3) protected double costPerDay. // cost for renting per day
4) protected double averageRating. // The average rating given by Customers
5) protected int numTimesChecked. // The number of times checked out by Customers
6) protected boolean checkedOut. // Whether the rental is currently checked out or not
7) protected Date releaseDate. // The release date for the Rental

Constructors:
------------
1) public Rental()
empty constructor

2) public Rental(double costPerDay, String title, String genre, double averageRating, int numTimesChecked, Date releaseDate)
set's the properties appropriately


3) public Rental(double costPerDay, String title, String genre, Date releaseDate)
-set's the properties appropriately
-set's the averageRating to 0
-set's the numTimesChecked to 0
(HINT: Use the constructor already defined)

Methods:
--------
get/set methods for all the properties (you should be able to figure out the return types/parameters):

-getReleaseDate/setReleaseDate

-getTitle/setTitle

-getGenre/setGenre

-getNumTimesChecked/setNumTimesChecked

-getAverageRating/setAverageRating

-getCostPerDay/setCostPerDay

---------------------------------------
METHODS FOR CHECKING OUT/IN A RENTAL:
---------------------------------------

-public boolean isCheckedOut()
Returns true if rental has been checked out, false if it hasn't.

-public void checkOut()
Checks out the rental.
Sets the checkout variable to true, and increments the numTimesChecked variable

-public double checkIn(int numDays, double rating)
Checks in the rental.
Sets the checkout variable to false.
Updates the averageRating by including the rating given by the Customer
returns the total cost for renting (use numDays and costPerDay)

----------------------
INTERFACE METHODS:
----------------------
-public int compareTo(Rental rental)
Does comparisons based on the title. (HINT: The String class also implements Comparable)

-public int compare(Rental rental1, Rental rental2)
Does comparisons based on popularity (numTimesChecked)
If rental1's popularity < rental2's popularity return 1
If rental1's popularity > rental2's popularity return -1
else return 0

-toString() - The toString() method is public and returns a String.
It should return a String in this format:

title, Genre: genre, Rating: averageRating, Times Checked Out: numTimesChecked, Release Date: releaseDate

Explanation / Answer

class Video { protected String myTitle; // name of the item protected int myLength; // number of minutes protected boolean myIsAvail; // is the tape in the store? public Video(String title, int len) { myTitle = title; myLength = len ; myIsAvail = true; } public String toString() { return myTitle + ", " + myLength + " min. available: " + myIsAvail; } } class Movie extends Video { protected String myDirector; // name of the director protected String myRating; // G, PG, R, or X // constructor public Movie(String title, int len, String dir, String rating) { // use the super class' constructor super(title, len); // initialize what's new to Movie myDirector = dir; myRating = rating; } } class VideoStore { public static void main (String args[]) { Video item1 = new Video("Juiced on Java", 90 ); Movie item2 = new Movie("Just Java", 120, "Gosling", "PG" ); System.out.println(item1.toString()); System.out.println(item2.toString()); } public Movie(String title, int len, String dir, String rating) { // use the super class' constructor super(title, len); // initialize what's new to Movie myDirector = dir; myRating = rating; } public Movie(String title, int len, String dir, String rating) { // initialize the inherited members myTitle = title; myLength = len ; myIsAvail = true; // initialize members unique to Movie myDirector = dir; myRating = rating; }