java eclipse project Write the code for class RentalItem . This class has three
ID: 3707280 • Letter: J
Question
java eclipse project
Write the code for class RentalItem. This class has three private data members: id of int type, description of String type, and processingFee of double type. Provide the default constructor and the constructor with all parameters. Provide a getter and setter for each data member. All data are private and all methods are public.
Code an interface named Rentable, which contains one abstract method named calcRentalFee(), which return double type and takes no formal parameter.
Write a subclass Car that extends from RentalItem. This class has two private data: mile travelled of int type, and charges per mile of double type. Provide constructors and getters and setters as usual. Provide an effector that overrides the abstract method in interface Rentable. The rental fee of a car is calculated by adding the processing fee to the product of multiplying miles travelled with charge per mile.
Write a subclass Tool that extends from RentalItem. This class has two private data: days rent of int type, and daily rental fee of double type. Provide constructors and getters and setters as usual. Provide an effector that overrides the abstract method in interface Rentable. The rental fee of a tool is calculated by adding the processing fee to the product of multiplying days rent with daily rental fee.
Explanation / Answer
// interface with one method
interface Rentable {
double calcRentalFee();
}
public class RentalItem {
private int ID;
private String description;
private double processingFee;
public RentalItem() {
}
public RentalItem(int aID, String aDescription, double aProcessingFee) {
super();
ID = aID;
description = aDescription;
processingFee = aProcessingFee;
}
public int getID() {
return ID;
}
public void setID(int aID) {
ID = aID;
}
public String getDescription() {
return description;
}
public void setDescription(String aDescription) {
description = aDescription;
}
public double getProcessingFee() {
return processingFee;
}
public void setProcessingFee(double aProcessingFee) {
processingFee = aProcessingFee;
}
}
class Car extends RentalItem implements Rentable {
private int milesTraveled;
private double chargesPerMile;
public Car() {
}
public Car(int aMilesTraveled, double aChargesPerMile) {
super();
milesTraveled = aMilesTraveled;
chargesPerMile = aChargesPerMile;
}
public int getMilesTraveled() {
return milesTraveled;
}
public void setMilesTraveled(int aMilesTraveled) {
milesTraveled = aMilesTraveled;
}
public double getChargesPerMile() {
return chargesPerMile;
}
public void setChargesPerMile(double aChargesPerMile) {
chargesPerMile = aChargesPerMile;
}
@Override
public double calcRentalFee() {
// as per the requirement
return milesTraveled * chargesPerMile + getProcessingFee();
}
}
class Tool extends RentalItem implements Rentable{
private int daysRent;
private double dailyRentalFee;
public Tool(){
}
public Tool(int aDaysRent, double aDailyRentalFee) {
super();
daysRent = aDaysRent;
dailyRentalFee = aDailyRentalFee;
}
public int getDaysRent() {
return daysRent;
}
public void setDaysRent(int aDaysRent) {
daysRent = aDaysRent;
}
public double getDailyRentalFee() {
return dailyRentalFee;
}
public void setDailyRentalFee(double aDailyRentalFee) {
dailyRentalFee = aDailyRentalFee;
}
@Override
public double calcRentalFee() {
// as per the requirement
return daysRent*dailyRentalFee+getProcessingFee();
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.