Answered step by step
Verified Expert Solution
Question
1 Approved Answer
please comment the code. Thanks. public class Media public Media(String name, int year) a constructor which initializes the media with the provided name and publication
please comment the code. Thanks. public class Media
public Media(String name, int year) a constructor which initializes the media with the provided name and publication year.
- public String getName() retrieves the stored name of the media.
- public int getYear() retrieves the stored year of the media.
- @Override public boolean equals(Object other) indicates whether this media is the other media which is passed in as a parameter. Much like the String class's equals method, we define two instances of media as equal if their contents are the same, that is, if their names and publication years match. Tip: since the parameter other is an Object rather than a Media, it is recommended to first check whether other is an instanceof Media, and if it is, cast it to be a Media object.
- @Override public int hashCode() one of Java's unenforced requirements is that if we ever override an equals method, we must also override hashCode such that if two object are equal, they also have the same hash code. It is sufficent for this method to return getName().hashCode().
- @Override public String toString() displays information about the media as a string, in the format "NAME (YEAR)". For example:
The Imitation Game (2014)
Payment Task: public class Payment{
- public Payment(String cardNo, String name, int expMonth, int expYear) initializes the payment method with the provided credit card number, cardholder name, expiration month and expiration year. Behavior for out of bounds dates is not specified - including checks is recommended but will not be tested.
- public String getCardNo() returns the stored credit card number.
- public String getName() returns the stored cardholder name.
- public int getExpMonth() returns the stored expiration month.
- public int getExpYear() returns the stored expiration year.
- @Override public String toString() returns a string representation of the payment information in the format "#CARDNUMBER (NAME), exp MONTH/YEAR". For example:
#0011223344556677 (abc def ), exp 10/2025
public class Rental{
The class should contain the following:
- public Rental(Media media, Payment payment, LocalDate today, double fee) rents the specified media using the provided payment method, with the rental perod beginning on the provided date, using the specified rental fee. When the object is created, the media is assumed to be rented out.
- public Media getMedia() retrieves the media which has been rented.
- public Payment getPayment() retrieves the payment method used to rent the media.
- public LocalDate getRentDate() retrieves the date on which the media was rented.
- public double getFee() retrieves the rental fee.
- public double dropoff(LocalDate today) drops off the video on the current date and reports the total rental fee.
- public boolean isRented() returns true until the first time that dropoff is called, after which it returns false.
- public int daysRented(LocalDate today) if the rental has already been returned, then this method will indicate the total number of days that it was rented. Otherwise, this method will report the total number of days from the rental date until the date provided as a parameter. Tip: the following call will allow us to find the span of days between two LocalDate objects, firstDate and secondDate:
Period.between(firstDate, secondDate).getDays()
- public double getTotalFee(LocalDate today) computes the total fee for the rental. In this case, it simply returns the flat fee which was passed in when the object was created.
- @Override public String toString() returns information about the rental as a string, in the following format: "MEDIA, rented on DATE using PAYMENT"
- . For example:
The Imitation Game (2014) DVD [PG-13, 114 min], rented on 2019-09-15 using #0011223344556677 (abc def), exp 10/2025
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started