LAB 02 Bicycles The World\'s Greatest Cost Effective Healthy Green Fashionable T
ID: 3910216 • Letter: L
Question
LAB 02 Bicycles The World's Greatest Cost Effective Healthy Green Fashionable Transportation Solution Downtown Dallas, Texas has seen an explosion in a demand for bicycle rentals. You have decided to go into the bicycle rental business to satisfy the world's desire for cost effective healthy green transportation. Market studies have shown that hundreds of billions of people are interested in renting bicycles which will result in a huge number ofrentals from your bicyck rental stores. You need to develop a program that cakculates the rental charge for a bicycle rental based on the number of days the bicycle is rented and the bicycle type. You must use the following package name for developing the java program: package biclyclerentalstorepackage: There must be at least 2 java source code files that have the following names: BicycleRentalStoreMainClass.java Contains the main BicycleStoreMainclass BicycleRentalclass.java Contains the BicycleRentalClass base class and the extended classes based on bicyck type The program must create and use at east an amount of bicyce objects for each type of bicycle If you do not use this assignment's stated file names, class names, method names, variable names and package name, the assignment is an invalid submission and will be graded a 090. This program introduces inheritance by creating subclasses ofa BicycleRentalclass based on bicycle type Your program design solution will override the equals 0 and calculateRentalFees0 methods in the extended casses.Explanation / Answer
Below is your code.
BicycleRentalStoreMainClass.java
package bicyclerentalstorepackage;
public class BicycleRentalStoreMainClass {
public static void main(String args[]) {
BicycleRentalClass bicycles[] = new BicycleRentalClass[5];
bicycles[0] = new BicycleRentalStandardClass(1, BICYCLE_TYPE_ENUM.STANDARD);
bicycles[1] = new BicycleRentalRacerClass(2, BICYCLE_TYPE_ENUM.RACER);
bicycles[2] = new BicycleRentalMountainClass(3, BICYCLE_TYPE_ENUM.MOUNTAIN);
bicycles[3] = new BicycleRentalBmxClass(4, BICYCLE_TYPE_ENUM.BMX);
bicycles[4] = new BicycleRentalTandemClass(5, BICYCLE_TYPE_ENUM.TANDEM);
for (BicycleRentalClass b : bicycles) {
System.out.println("Bicyle Id: " + b.getBicycleId());
System.out.println("Bicyle Type: " + b.getBicycleType());
System.out.println("Rental Fee: " + b.getBicycleRentalFee());
System.out.println("Rental fee for 8 days: " + b.calculateRentalFees(8));
System.out.println();
}
}
}
BicycleRentalClass.java
package bicyclerentalstorepackage;
enum BICYCLE_TYPE_ENUM {
STANDARD, RACER, MOUNTAIN, BMX, TANDEM
}
class DAILY_BICYCLE_RENTAL_RATES_CLASS {
public static final double RENTAL_DAILY_FEE_STANDARD = 1.00;
public static final double RENTAL_DAILY_FEE_RACER = 1.50;
public static final double RENTAL_DAILY_FEE_MOUNTAIN = 1.79;
public static final double RENTAL_DAILY_FEE_BMX = 1.89;
public static final double RENTAL_DAILY_FEE_TANDEM = 2.10;
}
public abstract class BicycleRentalClass {
private int bicycleId;
private BICYCLE_TYPE_ENUM bicycleType;
private double bicycleRentalFee;
public BicycleRentalClass(int bicycleId, BICYCLE_TYPE_ENUM bicycleType, double bicycleRentalFee) {
this.bicycleId = bicycleId;
this.bicycleType = bicycleType;
this.bicycleRentalFee = bicycleRentalFee;
}
// getter methods
public int getBicycleId() {
return bicycleId;
}
// setter methods
public void setBicycleId(int bicycleId) {
this.bicycleId = bicycleId;
}
public BICYCLE_TYPE_ENUM getBicycleType() {
return bicycleType;
}
public void setBicycleType(BICYCLE_TYPE_ENUM bicycleType) {
this.bicycleType = bicycleType;
}
public double getBicycleRentalFee() {
return bicycleRentalFee;
}
public void setBicycleRentalFee(double bicycleRentalFee) {
this.bicycleRentalFee = bicycleRentalFee;
}
// override method
public abstract double calculateRentalFees(int daysToRent);
public boolean equals(BicycleRentalClass other) {
return bicycleId == other.getBicycleId();
}
}
// constructor
class BicycleRentalStandardClass extends BicycleRentalClass {
public BicycleRentalStandardClass(int bicycleId, BICYCLE_TYPE_ENUM bicycleType) {
super(bicycleId, bicycleType, DAILY_BICYCLE_RENTAL_RATES_CLASS.RENTAL_DAILY_FEE_STANDARD);
}
@Override
public double calculateRentalFees(int daysToRent) {
return daysToRent * getBicycleRentalFee();
}
}
class BicycleRentalRacerClass extends BicycleRentalClass {
public BicycleRentalRacerClass(int bicycleId, BICYCLE_TYPE_ENUM bicycleType) {
super(bicycleId, bicycleType, DAILY_BICYCLE_RENTAL_RATES_CLASS.RENTAL_DAILY_FEE_RACER);
}
@Override
public double calculateRentalFees(int daysToRent) {
return daysToRent * getBicycleRentalFee();
}
}
class BicycleRentalMountainClass extends BicycleRentalClass {
public BicycleRentalMountainClass(int bicycleId, BICYCLE_TYPE_ENUM bicycleType) {
super(bicycleId, bicycleType, DAILY_BICYCLE_RENTAL_RATES_CLASS.RENTAL_DAILY_FEE_MOUNTAIN);
}
@Override
public double calculateRentalFees(int daysToRent) {
return daysToRent * getBicycleRentalFee();
}
}
class BicycleRentalBmxClass extends BicycleRentalClass {
public BicycleRentalBmxClass(int bicycleId, BICYCLE_TYPE_ENUM bicycleType) {
super(bicycleId, bicycleType, DAILY_BICYCLE_RENTAL_RATES_CLASS.RENTAL_DAILY_FEE_BMX);
}
@Override
public double calculateRentalFees(int daysToRent) {
return daysToRent * getBicycleRentalFee();
}
}
class BicycleRentalTandemClass extends BicycleRentalClass {
public BicycleRentalTandemClass(int bicycleId, BICYCLE_TYPE_ENUM bicycleType) {
super(bicycleId, bicycleType, DAILY_BICYCLE_RENTAL_RATES_CLASS.RENTAL_DAILY_FEE_TANDEM);
}
@Override
public double calculateRentalFees(int daysToRent) {
return daysToRent * getBicycleRentalFee();
}
}
Output
Bicyle Id: 1
Bicyle Type: STANDARD
Rental Fee: 1.0
Rental fee for 8 days: 8.0
Bicyle Id: 2
Bicyle Type: RACER
Rental Fee: 1.5
Rental fee for 8 days: 12.0
Bicyle Id: 3
Bicyle Type: MOUNTAIN
Rental Fee: 1.79
Rental fee for 8 days: 14.32
Bicyle Id: 4
Bicyle Type: BMX
Rental Fee: 1.89
Rental fee for 8 days: 15.12
Bicyle Id: 5
Bicyle Type: TANDEM
Rental Fee: 2.1
Rental fee for 8 days: 16.8
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.