In: Computer Science
Rental Shop
A. Create an abstract class named SummerSportRental that is to be
used with for a summer sports rental
shop. The SummerSportRental class must have the properties of
newModel which takes on the type
boolean, and rentalCost which takes on the type double, and
rentalNumber which is an identification
number as an long integer.These member variables must all be
private!
It also must include the following member functions:
1. equals() which returns true if two SummerSportRental objects
have the same rentalNumber.
2. all of the appropriate get/set methods for each of the above
member variables. Make sure to have
data validation done on the set methods to prevent invalid/illegal
values from being passed into the
member variables. (Example: rentalCost should not be allowed to be
negative).
3. include an abstract method named lateCharge, that will only be
implemented in child classes that
inherit the SummerSportRental class.
B. Create three children classes that inherit the SummerSportRental
class, named WaterSkiRental,
PaddleboardRental, and BeachCruiserBikeRental.
The WaterSkiRental class should have one private member variable
named size as an integer that will be
used to store the size of the water ski in centimeters. Implement
the get/set method for this member
variable. The abstract method in the SummerSportRental class, named
lateCharge must be implemented to
charge a late charge of 10% of the rental cost. Be sure to include
a method named toString to output the
data stored in the member variables for this class. No main method
in the class allowed!
The PaddleboardRental class should have two private member variable
named size as an integer that will
be used to store the size of the paddle board in centimeters, and
another member variable named style as
an enumerated type with the values (SINGLE, DOUBLE to denote if the
paddle board is a single person
board or a two person board). Implement the get/set methods for
these member variables. The abstract
method in the SummerSportRental class, named lateCharge must be
implemented to charge a late charge
of 20% of the rental cost. Be sure to include a method named
toString to output the data stored in the
member variables for this class. No main method in the class
allowed!
The BeachCruiserBikeRental class should have two private member
variable named wheel_szie as an
integer that will be used for storing the wheel size in centimeters
of the beach cruiser bike, and another
member variable named capacity as an enumerated type with the
values (SINGLE, DOUBLE, TRIPLE
[which has a very stylin' side cart to it]) that stores the seating
capacity of the beach cruiser bike. Implement
the get/set methods for these member variables. The abstract method
in the SnowSportRental class, named
lateCharge must be implemented to charge a late charge of
(20+capacity*5)% (late charge for single=25%,
double=30%, triple=35%) of the rental cost. Be sure to include a
method named toString to output the data
stored in the member variables for this class. No main method in
the class allowed!
C. Create separate test class source files with their respective
main methods to test each implemented
method in the WaterSkiRental, PaddleboardRental, and
BeachCruiserBikeRental classes. The list below is
the minimums for the test cases for each of the child
classes:
WaterSkiRental:
1. equals() method
2. newModel ( test get and set )
3. rentalCost ( test get and set )
4. rentalNumber ( test get and set )
5. size ( test get and set )
6. lateCharge - make sure it adheres to the specifications
above.
7. toString ( test toString method )
A total of 11 tests for WaterSkiRental class ( tests 1-4 are
actually for the SummerSportRental class, and will
not need to be repeated for PaddleboardRental and
BeachCruiserBikeRental class test )
PaddleboardRental:
1. size ( test get and set )
2. style ( test get and set )
3. lateCharge - make sure it adheres to the specifications
above.
4. toString ( test toString method )
A total of four tests for PaddleboardRental class
BeachCruiserBikeRental:
1. wheel_size ( test get and set )
2. capacity ( test get and set )
3. lateCharge - make sure it adheres to the specifications
above.
4. toString ( test toString method )
A total of four tests for BeachCruiserBikeRental class
You are to submit:
Zipfile of your Final Project with the following name format:
LastName_FirstName_Final.zip
Programmer Documentation File
Note: make sure to thoroughly read through all of the requirements
for this project. Specifications will be
very strictly enforced.
How do I do this in JAVA?
SummerSportRental.java :
package Summer;
public abstract class SummerSportRental {
protected enum Types {SINGLE,DOUBLE,TRIPLE};
private boolean newModal;
private double rentalCost;
private long rentalNumber;
public SummerSportRental(){
newModal = false;
rentalCost = 0.0;
rentalNumber = 0;
}
public boolean equals(SummerSportRental obj){
if(this.rentalNumber ==
obj.rentalNumber){
return
true;
}
else{
return
false;
}
}
public boolean getNewModal(){
return newModal;
}
public void setNewModal(boolean model){
this.newModal = model;
}
public double getRentalCost(){
return rentalCost;
}
public void setRentalCost(double cost){
if(cost>0){
rentalCost =
cost;
}
else{
System.out.println("Invalid cost");
}
}
public long getRentalNumber(){
return rentalNumber;
}
public void setRentalNumber(long number){
if(number>0){
rentalNumber =
number;
}
else{
System.out.println("Invalid cost");
}
}
public abstract double lateCharge();
}
WaterSkiRental.java:
package Summer;
public class WaterSkiRental extends SummerSportRental {
private int size;
public WaterSkiRental(){
super();
size = 0;
}
public int getSize(){
return size;
}
public void setSize(int s){
if(s>0){
size = s;
}
else{
System.out.println("Invalid size");
}
}
public double lateCharge() {
double charge =
this.getRentalCost()*0.1;
return charge;
}
public String toString(){
String str = "The size of the water
ski is :" + size + " centimeters";
return str;
}
}
PaddleboardRental.java :
package Summer;
public class PaddleboardRental extends SummerSportRental {
private int size;
private Types style;
public PaddleboardRental(){
super();
size = 0;
style = Types.SINGLE;
}
public int getSize(){
return size;
}
public void setSize(int s){
if(s>0){
size = s;
}
else{
System.out.println("Invalid size");
}
}
public Types getStyle(){
return style;
}
public void setStyle(Types t){
if(t==Types.TRIPLE){
System.out.println("No three person paddlebord available");
}
else{
style = t;
}
}
public double lateCharge() {
double charge =
this.getRentalCost()*0.2;
return charge;
}
public String toString(){
String s = "";
switch (style) {
case SINGLE:
s =
"single";
break;
case DOUBLE:
s = "two";
break;
default:
break;
}
String str = "The size of the
paddle board is : " + size + " centimeters. \n" +
"The
paddle board is a " + s + " person board";
return str;
}
}
BeachCruiserBikeRental.java :
package Summer;
public class BeachCruiserBikeRental extends SummerSportRental
{
private int wheel_size;
private Types capacity;
public BeachCruiserBikeRental(){
super();
wheel_size = 0;
capacity = Types.SINGLE;
}
public int getWheelSize(){
return wheel_size;
}
public void setWheelSize(int size){
if(size>0){
wheel_size =
size;
}
else{
System.out.println("Invalid wheel size");
}
}
public Types getCapacity(){
return capacity;
}
public void setCapacity(Types t){
capacity = t;
}
public double lateCharge() {
double charge = 0.0;
if(capacity==Types.SINGLE){
charge =
this.getRentalCost()*0.25;
}
else
if(capacity==Types.DOUBLE){
charge =
this.getRentalCost()*0.3;
}
else {
charge =
this.getRentalCost()*0.35;
}
return charge;
}
public String toString(){
int cap = 0;
switch (capacity) {
case SINGLE:
cap = 1;
break;
case DOUBLE:
cap = 2;
break;
case TRIPLE:
cap = 3;
break;
default:
break;
}
String str = "the wheel size is : "
+ wheel_size + " centimeters of the beach cruiser bike. \n" +
"the seating capacity of the beach cruiser bike
is : " + cap;
return str;
}
}
test.java:
package Summer;
import Summer.SummerSportRental.Types;
public class test {
public static void main(String[] args){
WaterSkiRental ws1 = new
WaterSkiRental();
ws1.setNewModal(true);
ws1.setRentalCost(15);
ws1.setRentalNumber(2456);
ws1.setSize(50);
WaterSkiRental ws2 = new
WaterSkiRental();
ws2.setNewModal(false);
ws2.setRentalCost(8);
ws2.setRentalNumber(2156);
ws2.setSize(45);
System.out.println(ws1.equals(ws2));
System.out.println(ws1.getNewModal());
System.out.println(ws1.getRentalCost());
System.out.println(ws1.getRentalNumber());
System.out.println(ws1.getSize());
System.out.println(ws1.lateCharge());
System.out.println(ws1.toString());
PaddleboardRental pb1 = new
PaddleboardRental();
pb1.setSize(130);
pb1.setStyle(Types.DOUBLE);
pb1.setRentalCost(27);
System.out.println(pb1.getSize());
System.out.println(pb1.getStyle());
System.out.println(pb1.lateCharge());
System.out.println(pb1.toString());
BeachCruiserBikeRental bcb1 = new
BeachCruiserBikeRental();
bcb1.setWheelSize(130);
bcb1.setCapacity(Types.TRIPLE);
bcb1.setRentalCost(41);
System.out.println(bcb1.getWheelSize());
System.out.println(bcb1.getCapacity());
System.out.println(bcb1.lateCharge());
System.out.println(bcb1.toString());
}
}