-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVehicle.java
More file actions
42 lines (35 loc) · 995 Bytes
/
Vehicle.java
File metadata and controls
42 lines (35 loc) · 995 Bytes
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
public abstract class Vehicle implements Rentable {
protected String vehicleID;
protected String modelName;
protected double rentalRate;
protected boolean isRented;
public Vehicle(String vehicleID, String modelName, double rentalRate) {
this.vehicleID = vehicleID;
this.modelName = modelName;
this.rentalRate = rentalRate;
this.isRented = false;
}
public String getVehicleID() {
return vehicleID;
}
public boolean isRented() {
return isRented;
}
public abstract double calculateRentalCost(int days);
@Override
public boolean rentVehicle() {
if (!isRented) {
isRented = true;
return true;
}
return false;
}
@Override
public void returnVehicle() {
isRented = false;
}
@Override
public String toString() {
return this.getClass().getSimpleName() + " - " + modelName + " (ID: " + vehicleID + ")";
}
}