Question

In: Computer Science

Bicycles – The World’s Greatest Cost Effective Healthy GreenFashionable Transportation Solution Downtown Dallas, Texas has...

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 of rentals from your bicycle rental stores.

You need to develop a program that calculates 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 bicyclerentalstorepackage;

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 bicycle type.

The program must create and use at least an amount of bicycle 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 0%.

This program introduces inheritance by creating subclasses of a BicycleRentalClass based on bicycle type. Your program design solution will override the equals() and calculateRentalFees() methods in the extended classes.

Solutions

Expert Solution

//////////////////////////////////////////////////////////////BicycleRentalClass.jaav//////////////////////////////////////////////////////////////////////////////

package bicyclerentalstorepackage;

import bicyclerentalstorepackage.BicycleRentalStoreMainClass.BICYCLE_TYPE_ENUM;

public abstract class BicycleRentalClass {

private int bicycleId;

private BICYCLE_TYPE_ENUM bicyleType;

private double bicyleRentalFee;

public double getBicyleRentalFee() {

return bicyleRentalFee;

}

// bicycleRentalFee can not be negative. In case of -ve exception is thrown

public void setBicyleRentalFee(double bicyleRentalFee) {

if (bicyleRentalFee < 0) {

throw new IllegalArgumentException();

} else {

this.bicyleRentalFee = bicyleRentalFee;

}

}

// constructor with bicyleId and bicyleType

public BicycleRentalClass(int bicycleId, BICYCLE_TYPE_ENUM bicyleType) {

super();

this.bicycleId = bicycleId;

this.bicyleType = bicyleType;

}

public int getBicycleId() {

return bicycleId;

}

public void setBicycleId(int bicycleId) {

this.bicycleId = bicycleId;

}

public BICYCLE_TYPE_ENUM getBicyleType() {

return bicyleType;

}

public void setBicyleType(BICYCLE_TYPE_ENUM bicyleType) {

this.bicyleType = bicyleType;

}

/**

*

* @param daysToRent

* indicates number of days the bicycle is to be rented

* @return rental charges

*/

public abstract double calculateRentalFee(int daysToRent);

@Override

public int hashCode() {

final int prime = 31;

int result = 1;

result = prime * result + bicycleId;

return result;

}

/**

* compares two BicycleRentalClasses by their ids

*/

public boolean equals(BicycleRentalClass otherBicycleRentalClassObj) {

if (this == otherBicycleRentalClassObj)

return true;

if (otherBicycleRentalClassObj == null)

return false;

if (bicycleId != otherBicycleRentalClassObj.bicycleId)

return false;

return true;

}

}

////////////////////////////////////////////////////////////End BicycleRentalClass.java//////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////BicycleRentalStoreMainClass.java////////////////////////////////////////////////////////////////

package bicyclerentalstorepackage;

public class BicycleRentalStoreMainClass {

public enum BICYCLE_TYPE_ENUM {

STANDARD, RACER, MOUNTAIN, BMX;

}

private class DAILY_BICYCLE_REANTAL_RATE_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 void main(String args[]) {

testStandardCycle();

BicycleRentalRacerClass racerBicycle = testRacerCycle();

testMountainCycle();

BicycleRentalBmxClass bmxBicycle = testBmxCycle();

testEquals(racerBicycle, bmxBicycle);

// Test Negative Value for number of days

testNegativeNumOfDays();

testNegativeCycleRent();

}

private static void testEquals(BicycleRentalRacerClass racerBicycle, BicycleRentalBmxClass bmxBicycle) {

// Test for equals(): The two bicycles are not equal as their Ids are different

boolean result = bmxBicycle.equals(racerBicycle);

System.out.println("\nIs BmxCycle (id:" + bmxBicycle.getBicycleId() + ") equals to RacerCycle(id:"

+ racerBicycle.getBicycleId() + ") ? " + result);

// Test for equals(): The two bicycles are Equal as their Ids are same

bmxBicycle.setBicycleId(2);

result = bmxBicycle.equals(racerBicycle);

System.out.println("Is BmxCycle (id:" + bmxBicycle.getBicycleId() + ") equals to RacerCycle(id:"

+ racerBicycle.getBicycleId() + ") ? " + result + "\n");

}

private static void testStandardCycle() {

BicycleRentalStandardClass stdBicycle = new BicycleRentalStandardClass(1, BICYCLE_TYPE_ENUM.STANDARD);

stdBicycle.setBicyleRentalFee(DAILY_BICYCLE_REANTAL_RATE_CLASS.RENTAL_DAILY_FEE_STANDARD);

// bicycle id is set in constructor. check it by calling getBicycleId(). It

// should be 1

System.out.println("stdBicycle Id=" + stdBicycle.getBicycleId());

// bicycle Type is set in constructor. check it by calling getBicyleType(). It

// should be STANDARD

System.out.println("stdBicycle Type=" + stdBicycle.getBicyleType());

// Going to Rent the standard Bicycle for 3 days so the outcome should be 3

double rent = stdBicycle.calculateRentalFee(3);

System.out.println("Rent for Standard Bicycle for 3 days is =" + rent);

}

private static BicycleRentalRacerClass testRacerCycle() {

double rent;

BicycleRentalRacerClass racerBicycle = new BicycleRentalRacerClass(2, BICYCLE_TYPE_ENUM.RACER);

racerBicycle.setBicyleRentalFee(DAILY_BICYCLE_REANTAL_RATE_CLASS.RENTAL_DAILY_FEE_RACER);

// bicycle id is set in constructor. check it by calling getBicycleId(). It

// should be 2

System.out.println("\nracerBicycle Id=" + racerBicycle.getBicycleId());

// bicycle Type is set in constructor. check it by calling getBicyleType(). It

// should be RACER

System.out.println("racerBicycle Type=" + racerBicycle.getBicyleType());

// Going to Rent the Racer Bicycle for 14 days so the outcome should be 21

rent = racerBicycle.calculateRentalFee(14);

System.out.println("Rent for Standard Bicycle for 14 days is =" + rent);

return racerBicycle;

}

private static void testMountainCycle() {

double rent;

BicycleRentalMountainClass mountainBicycle = new BicycleRentalMountainClass(3, BICYCLE_TYPE_ENUM.MOUNTAIN);

mountainBicycle.setBicyleRentalFee(DAILY_BICYCLE_REANTAL_RATE_CLASS.RENTAL_DAILY_FEE_MOUNTAIN);

// bicycle id is set in constructor. check it by calling getBicycleId(). It

// should be 3

System.out.println("\nmountainBicycle Id=" + mountainBicycle.getBicycleId());

// bicycle Type is set in constructor. check it by calling getBicyleType(). It

// should be MOUNTAIN

System.out.println("mountainBicycle Type=" + mountainBicycle.getBicyleType());

// Going to Rent the Mountain Bicycle for 7 days so the outcome should be 12.53

rent = mountainBicycle.calculateRentalFee(7);

System.out.println("Rent for Mountain Bicycle for 7 days is =" + rent);

}

private static BicycleRentalBmxClass testBmxCycle() {

double rent;

BicycleRentalBmxClass bmxBicycle = new BicycleRentalBmxClass(4, BICYCLE_TYPE_ENUM.BMX);

bmxBicycle.setBicyleRentalFee(DAILY_BICYCLE_REANTAL_RATE_CLASS.RENTAL_DAILY_FEE_BMX);

// bicycle id is set in constructor. check it by calling getBicycleId(). It

// should be 4

System.out.println("\nBmxCycle Id=" + bmxBicycle.getBicycleId());

// bicycle Type is set in constructor. check it by calling getBicyleType(). It

// should be BMX

System.out.println("BmxCycle Type=" + bmxBicycle.getBicyleType());

// Going to Rent the Bmx Bicycle for 8 days so the outcome should be 15.12

rent = bmxBicycle.calculateRentalFee(8);

System.out.println("Rent for Bmx Bicycle for 8 days is =" + rent);

return bmxBicycle;

}

// Going to Rent the Bmx Bicycle for negative number of days so the outcome

// should be an exception

private static void testNegativeNumOfDays() {

double rent;

BicycleRentalBmxClass bmxBicycle = new BicycleRentalBmxClass(4, BICYCLE_TYPE_ENUM.BMX);

bmxBicycle.setBicyleRentalFee(DAILY_BICYCLE_REANTAL_RATE_CLASS.RENTAL_DAILY_FEE_BMX);

try {

rent = bmxBicycle.calculateRentalFee(-2);

System.out.println("Rent for Bmx Bicycle for -2 days is =" + rent);

} catch (IllegalArgumentException e) {

System.out.println("Number of days must be positive number " + e);

}

}

// Going to Rent the Bmx Bicycle for 2 days but the rent is negative so there

// shud be an exception

private static void testNegativeCycleRent() {

double rent;

BicycleRentalBmxClass bmxBicycle = new BicycleRentalBmxClass(4, BICYCLE_TYPE_ENUM.BMX);

try {

bmxBicycle.setBicyleRentalFee(-20);

rent = bmxBicycle.calculateRentalFee(2);

System.out.println("Rent for Bmx Bicycle for 2 days is =" + rent);

} catch (IllegalArgumentException e) {

System.out.println("Rent must be positive number " + e);

}

}

}

//////////////////////////////////////////////////////End BicycleRentalStoreMainClass.java////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////BicycleRentalBmxClass.java///////////////////////////////////////////////////////////////////////////////////

package bicyclerentalstorepackage;

import bicyclerentalstorepackage.BicycleRentalStoreMainClass.BICYCLE_TYPE_ENUM;

public class BicycleRentalBmxClass extends BicycleRentalClass {

// Constructor with bicycleId and bicycleType which calls the constructor of the

// BicycleRentalClass

public BicycleRentalBmxClass(int bicycleId, BICYCLE_TYPE_ENUM bicyleType) {

super(bicycleId, bicyleType);

}

@Override

public double calculateRentalFee(int daysToRent) {

double rent = 0;

if (daysToRent >= 0) {

rent = daysToRent * getBicyleRentalFee();

} else {

System.out.println("Please enter number of days 0 or greater than 0");

throw new IllegalArgumentException();

}

return rent;

}

}

/////////////////////////////////////////////End BicycleRentalBmxClass.java///////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////BicycleRentalMountainClass.java//////////////////////////////////////////////////////////////////

package bicyclerentalstorepackage;

import bicyclerentalstorepackage.BicycleRentalStoreMainClass.BICYCLE_TYPE_ENUM;

public class BicycleRentalMountainClass extends BicycleRentalClass {

// Constructor with bicycleId and bicycleType which calls the constructor of the

// BicycleRentalClass

public BicycleRentalMountainClass(int bicycleId, BICYCLE_TYPE_ENUM bicyleType) {

super(bicycleId, bicyleType);

}

@Override

public double calculateRentalFee(int daysToRent) {

double rent = 0;

if (daysToRent >= 0) {

rent = daysToRent * getBicyleRentalFee();

} else {

System.out.println("Please enter number of days 0 or greater than 0");

throw new IllegalArgumentException();

}

return rent;

}

///////////////////////////////////////////////////////End BicycleRentalMountainClass.java//////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////BicycleRentalRacerClass.java///////////////////////////////////////////////////////////////////////

package bicyclerentalstorepackage;

import bicyclerentalstorepackage.BicycleRentalStoreMainClass.BICYCLE_TYPE_ENUM;

public class BicycleRentalRacerClass extends BicycleRentalClass {

// Constructor with bicycleId and bicycleType which calls the constructor of the

// BicycleRentalClass

public BicycleRentalRacerClass(int bicycleId, BICYCLE_TYPE_ENUM bicyleType) {

super(bicycleId,bicyleType);

}

@Override

public double calculateRentalFee(int daysToRent) {

double rent = 0;

if (daysToRent >= 0) {

rent = daysToRent * getBicyleRentalFee();

} else {

System.out.println("Please enter number of days 0 or greater than 0");

throw new IllegalArgumentException();

}

return rent;

}

}

///////////////////////////////////////////////End BicycleRentalRacerClass.java////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////BicycleRentalStandardClass.java////////////////////////////////////////////////////////////////////////////

package bicyclerentalstorepackage;

import bicyclerentalstorepackage.BicycleRentalStoreMainClass.BICYCLE_TYPE_ENUM;

public class BicycleRentalStandardClass extends BicycleRentalClass {

// Constructor with bicycleId and bicycleType which calls the constructor of the

// BicycleRentalClass

public BicycleRentalStandardClass(int bicycleId, BICYCLE_TYPE_ENUM bicyleType) {

super(bicycleId, bicyleType);

}

@Override

public double calculateRentalFee(int daysToRent) {

double rent = 0;

if (daysToRent >= 0) {

rent = daysToRent * getBicyleRentalFee();

} else {

System.out.println("Please enter number of days 0 or greater than 0");

throw new IllegalArgumentException();

}

return rent;

}

}

///////////////////////////////////////////////End BicycleRentalStandardClass.java////////////////////////////////////////////////////////////////////////////


Related Solutions

Floyd’s Bumpers has distribution centers in Lafayette, Indiana; Charlotte, North Carolina; Los Angeles, California; Dallas, Texas;...
Floyd’s Bumpers has distribution centers in Lafayette, Indiana; Charlotte, North Carolina; Los Angeles, California; Dallas, Texas; and Pittsburgh, Pennsylvania. Each distribution center carries all products sold. Floyd’s customers are auto repair shops and larger auto parts retail stores. You are asked to perform an analysis of the customer assignments to determine which of Floyd’s customers should be assigned to each distribution center. The rule for assigning customers to distribution centers is simple: A customer should be assigned to the closest...
Floyd’s Bumpers has distribution centers in Lafayette, Indiana; Charlotte, North Carolina; Los Angeles, California; Dallas, Texas;...
Floyd’s Bumpers has distribution centers in Lafayette, Indiana; Charlotte, North Carolina; Los Angeles, California; Dallas, Texas; and Pittsburgh, Pennsylvania. Each distribution center carries all products sold. Floyd’s customers are auto repair shops and larger auto parts retail stores. You are asked to perform an analysis of the customer assignments to determine which of Floyd’s customers should be assigned to each distribution center. The rule for assigning customers to distribution centers is simple: A customer should be assigned to the closest...
Floyd’s Bumpers has distribution centers in Lafayette, Indiana; Charlotte, North Carolina; Los Angeles, California; Dallas, Texas;...
Floyd’s Bumpers has distribution centers in Lafayette, Indiana; Charlotte, North Carolina; Los Angeles, California; Dallas, Texas; and Pittsburgh, Pennsylvania. Each distribution center carries all products sold. Floyd’s customers are auto repair shops and larger auto parts retail stores. You are asked to perform an analysis of the customer assignments to determine which of Floyd’s customers should be assigned to each distribution center. The rule for assigning customers to distribution centers is simple: A customer should be assigned to the closest...
Floyd’s Bumpers has distribution centers in Lafayette, Indiana; Charlotte, North Carolina; Los Angeles, California; Dallas, Texas;...
Floyd’s Bumpers has distribution centers in Lafayette, Indiana; Charlotte, North Carolina; Los Angeles, California; Dallas, Texas; and Pittsburgh, Pennsylvania. Each distribution center carries all products sold. Floyd’s customers are auto repair shops and larger auto parts retail stores. You are asked to perform an analysis of the customer assignments to determine which of Floyd’s customers should be assigned to each distribution center. The rule for assigning customers to distribution centers is simple: A customer should be assigned to the closest...
Floyd’s Bumpers has distribution centers in Lafayette, Indiana; Charlotte, North Carolina; Los Angeles, California; Dallas, Texas;...
Floyd’s Bumpers has distribution centers in Lafayette, Indiana; Charlotte, North Carolina; Los Angeles, California; Dallas, Texas; and Pittsburgh, Pennsylvania. Each distribution center carries all products sold. Floyd’s customers are auto repair shops and larger auto parts retail stores. You are asked to perform an analysis of the customer assignments to determine which of Floyd’s customers should be assigned to each distribution center. The rule for assigning customers to distribution centers is simple: A customer should be assigned to the closest...
Which energy sector (Residential+Commerical, Transportation, Industrial Sector) has the greatest need for energy conservation and why?...
Which energy sector (Residential+Commerical, Transportation, Industrial Sector) has the greatest need for energy conservation and why? Which energy sector is most likely to achieve significant energy conservation and Why?
Frankenstein Bicycles has an unlevered cost of equity of 0.21. Their bonds are worth 472,341 and...
Frankenstein Bicycles has an unlevered cost of equity of 0.21. Their bonds are worth 472,341 and their equity is worth 446,790. The debt rate is 0.02 and their tax rate is 0.40. What is Frankenstein's cost of levered equity?
Frankenstein Bicycles has an unlevered cost of equity of 0.15. Their bonds are worth 435,721 and...
Frankenstein Bicycles has an unlevered cost of equity of 0.15. Their bonds are worth 435,721 and their equity is worth 323,527. The debt rate is 0.02 and their tax rate is 0.22. What is Frankenstein's cost of levered equity?
Question? Take a new company in Texas that has a higher cost of production for soft...
Question? Take a new company in Texas that has a higher cost of production for soft drinks than current soft drink producers in the rest of the world. The sector lobbies the government of TX congress and claims that if they are protected by a tariff they can learn better methods and eventually become a competitive soft-drink producer. label the cost and benefits of adopting this policy. What will need to be evaluated in choosing whether this would be a...
A firm has sold 55,555 bicycles in 2020 that has variable cost of $199.55 for $299.99 each. The company's fixed cost for the year was $3,000,000.
A firm has sold 55,555 bicycles in 2020 that has variable cost of $199.55 for $299.99 each. The company's fixed cost for the year was $3,000,000. Show your work here below. To find Profit, compute the following first.1. Total Variable Cost (TVC) ______2. Total Cost (TC) _____3. Total Revenue (TR) ______4. Profit = ____
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT