-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMotorBike.java
82 lines (70 loc) · 2.32 KB
/
MotorBike.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*
/*
* Subclass MotorBike. This is an extension of the class Vehicle. TCSS 305 - Rentz
*/
package model.vehicles;
import java.math.BigDecimal;
import java.util.Objects;
/**
* @author hphobbs
* @version Winter 2020
*/
public class MotorBike extends AbstractVehicle {
/** Field variable to represent the touring fee. */
public static final BigDecimal TOURING_FEE = new BigDecimal(5);
/** Field variable to represent touring. */
private final boolean myTouringStatus;
/**
* Parameterized constructor.
*
* @param theName
* @param theVin
* @param theRentalStatus
* @param theTouringStatus
*/
public MotorBike(final String theName, final String theVin, final boolean theRentalStatus,
final boolean theTouringStatus) {
super(theName, theVin);
myTouringStatus = theTouringStatus;
}
/** Calculates the rental amount. */
@Override
public BigDecimal calculateRentalAmount() {
BigDecimal rentalAmount = BIKE_FARE;
if (myTouringStatus) {
rentalAmount = rentalAmount.add(TOURING_FEE);
}
return rentalAmount;
}
/** @return a string representation of the motorbike */
public String toString() {
return "MotorBike (ID:" + getMyVehicleID() + ", Name:" + getMyName() + ", VIN:"
+ getMyVIN() + ", CanRent?:" + getMyRentalStatus() + ", IsTouring?:"
+ myTouringStatus + ")";
}
/**
* Redefinition of the equals method from the one of the parent class.
*
* @param theOtherVehicle
* @return false
*/
public boolean equals(final Object theOtherVehicle) {
boolean result = false;
if (!(theOtherVehicle instanceof MotorBike)) {
result = false;
} else {
final MotorBike otherMotorBike = (MotorBike) theOtherVehicle;
result = super.equals(otherMotorBike)
&& myTouringStatus == otherMotorBike.myTouringStatus;
}
return result;
}
/**
* Redifinition of the hashcode method from the one of the parent class.
*
* @return hashcode
*/
public int hashCode() {
return super.hashCode() + Objects.hash(myTouringStatus);
}
}