-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRentalSystem.java
67 lines (54 loc) · 1.55 KB
/
RentalSystem.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
package Test1;
import java.util.ArrayList;
import java.util.List;
public class RentalSystem {
private List<Vehicle> availableVehicles;
private List<Vehicle> rentedVehicles;
public RentalSystem() {
availableVehicles = new ArrayList<>();
rentedVehicles = new ArrayList<>();
}
//to add vehicles to rental system
public void addVehicle(Vehicle vehicle) {
availableVehicles.add(vehicle);
}
public List<Vehicle> getAvailableVehicles(){
return availableVehicles;
}
public List<Vehicle> getRentedVehicles(){
return rentedVehicles;
}
//to rent vehicle
public void rentVehicle(Vehicle vehicle) {
if(availableVehicles.contains(vehicle)) {
availableVehicles.remove(vehicle);
rentedVehicles.add(vehicle);
}
}
//to return rented vehicle
public void returnVehicle(Vehicle vehicle) {
if(rentedVehicles.contains(vehicle)) {
rentedVehicles.remove(vehicle);
availableVehicles.add(vehicle);
}
}
//To display available and rented vehicles
public void displayRentalInfo() {
System.out.println("Available vehicles: ");
for(Vehicle av : availableVehicles) {
av.displayInfo();
System.out.println();
}
System.out.println("Rented vehicles: ");
for(Vehicle rv : rentedVehicles) {
rv.displayInfo();
System.out.println();
}
}
//To calculate total rental cost
public double calculateRentalCost(Vehicle vehicle, int rentalDuration) {
double rentalRate = vehicle.getRentalRate();
double totalCost = rentalRate * rentalDuration;
return totalCost;
}
}