222k views
5 votes
Create a Rental class for a company who rents moving trucks for people with the following 3 attributes: name (of type string), number of days (of type integer), and additional fees (of type double). [The additional fees are for things like moving boxes purchased as part of the rental.] Make all the getters and setters as well as a full constructor for this class that takes all three variables and sets them. Make an abstract method called payRental() in this class as well.

Create a weekDayRental class that inherits from the Rental and takes all three values in its constructor and passes them to the parent. Override the payRental() method in this class that multiplies the number of days by $79 [fixed amount the company advertises] and adds the additional fees and prints this value for the user.
Create a weekEndRental class with a weekend rate (of type double) that inherits from the Rental and takes this value as well as the three values for a Rental in its constructor and passes them to the parent. Make a getter and setter for the weekend rate. Override the payRental() method in this class that multiplies the number or days by the weekend rate and adds the additional fees and prints this value for the user.

User Onik IV
by
8.5k points

1 Answer

1 vote

Final answer:

The creating a base class with attributes for a truck rental company, and two sub classes that calculate the cost for weekday and weekend rentals by overriding an abstract pay Rental() method.

Step-by-step explanation:

The student is asking for assistance in creating a Rental class with specific attributes and methods, and then creating two subclasses, weekDayRental and weekEndRental, that inherit from the Rental class and override the payRental() method. This task requires understanding of object-oriented programming (OOP) concepts in a programming language that supports inheritance, like Java or C#.

The classes should have attributes for the truck rental company, such as name, number of days, and additional fees. Moreover, the student must use the inheritance feature by creating subclasses which derive from the Rental base class and override the abstract payRental() method according to the type of rental.

In the weekDayRental class, the payRental() method calculates the total cost by multiplying the number of days by a fixed rate and adding additional fees. In the weekEndRental class, the method uses a weekend rate instead of a fixed rate. Both subclasses should call the constructor of the parent class in their own constructors, and the weekEndRental class should also include getters and setters for the weekend rate attribute.

User Jarek Kardas
by
9.1k points