Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PLEASE DO IN JAVA ALREADY FINISHED RENTAL TASK JUST INCLUDED BECAUSE DAILY RENTAL EXTENDS IT THANKS Rental Task: public class Rental ( 15pts ) The

PLEASE DO IN JAVA ALREADY FINISHED RENTAL TASK JUST INCLUDED BECAUSE DAILY RENTAL EXTENDS IT THANKS

Rental Task: public class Rental

(15pts) The point of having rentable media is to be able to rent it out. Thus, we will create a class which will hold information about a particular rental instance. To rent media, we would need to know what we are renting (the media), the payment method we will use, the date of the rental and the base rental fee. The class will provide us some capabilities related to rentals, such as determining how long the media has been rented, dropping off the rental, determining the total fee, and asking whether the rental has been returned. We assume that the rental period has begun the moment the object is created, and lasts until dropoff is called. The current fee can be calculated using getTotalFee both before and after the media is dropped off.

The rental is initially rented out, but stops being rented out the moment dropoff is called. Thus, our implementation will need to have some way of telling us whether the rental is rented out or returned. There are a number of ways to implement this, including using a boolean flag, or using the dropoff date as an indicator.

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 (i.e. the fee which we passed in when we created the rental). If the video has not already been dropped off, then this method will set the return date as the current date passed in as a parameter, and then it will return the total fee as given by the getTotalFee method. If the video has already been return previously, then this method would have no additional effect, but would still report back the total 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:

DailyRental Task: public class DailyRental extends Rental

(15pts) A daily rental is a type of rental in which the fees are handled on a daily basis. Instead of having one flat fee, the fee is a daily charge which depends on how many days the video has been rented. Most of this class is the same as the Rental class which it derives from, except that the fee calculation is more sophisticated. Thus, it will override the existing getTotalFee method. Notice that by doing this, the method will be retroactively replaced whereever it had been used previously, including the dropoff method, without any additional action on our part. We will also include the option of providing a credit (i.e. a promo code) which is applied to the rental. This class will contain the following methods:

  • public DailyRental(Media media, Payment payment, LocalDate today, double fee, double credit) a constructor which will initialize the rental with the given information about media, payment method, rental date, fee (to be interpreted as a daily fee), and promo credit.
  • public DailyRental(Media media, Payment payment, LocalDate today, double fee) a constructor which will initialize the rental with the given information about media, payment method, rental date, and fee (to be interpreted as a daily fee). The promo credit should default to zero in this version.
  • public double getCredit() retrieves the promo credit value.
  • @Override public double getTotalFee(LocalDate today) replaces the flat-rate total fee calculation with a daily fee calculation. The fee will be given by the product of the number of days the video has been rented (hint: we have a method for that) and the daily rental fee. Assume that the customer must be charged for at least one day, so if the video has been rented for less than one day, treat it as a 1-day rental. After the daily rental rate is calculated, the promo credit is subtracted, with a minimum bound of zero (if subtracting the promo credit results in a negative charge, this method will return zero). Thus, for example, if a video has been rented for 2 days with a fee of $1.50 and a credit of $0.50, then the method will return 2 * $1.50 - $0.50 = $2.50.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Marketing The New Profit Frontier

Authors: Ed Burnett

1st Edition

0964535629, 978-0964535626

More Books

Students also viewed these Databases questions

Question

3. Comment on how diversity and equality should be managed.

Answered: 1 week ago

Question

describe the legislation that addresses workplace equality

Answered: 1 week ago