-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustomer.java
More file actions
94 lines (80 loc) · 2.84 KB
/
Copy pathCustomer.java
File metadata and controls
94 lines (80 loc) · 2.84 KB
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
83
84
85
86
87
88
89
90
91
92
93
94
package ass2_1231279_1;
class Customer {
private String name;
private int id;
private String licenseNumber;
private int maxVehicles;
private Vehicle[] vehiclesRented;
private int currentRentedCount;
public Customer() {}
public Customer(String name, int id, String licenseNumber, int maxVehicles) {
this.name = name;
this.id = id;
this.licenseNumber = licenseNumber;
this.maxVehicles = maxVehicles;
this.vehiclesRented = new Vehicle[maxVehicles];
this.currentRentedCount = 0;
}
public String getName() {
return name;
}
public int getId() {
return id;
}
public int getMaxVehicles() {
return maxVehicles;
}
public int getCurrentRentedCount() {
return currentRentedCount;
}
public void rentVehicle(Vehicle vehicle) {
if (vehicle.isAvailable()) {
if (currentRentedCount < maxVehicles) {
vehiclesRented[currentRentedCount] = vehicle;
vehicle.setAvailable(false);
currentRentedCount++;
System.out.println("Vehicle " + vehicle.getRegistrationNumber() + " rented successfully.");
} else {
System.out.println("You have reached your rental limit.");
}
} else {
System.out.println("Vehicle " + vehicle.getRegistrationNumber() + "is not available for rent.");
}
}
public void returnVehicle(Vehicle vehicleToReturn) {
for (int i = 0; i < currentRentedCount; i++) {
if (vehiclesRented[i].getRegistrationNumber().equals(vehicleToReturn)) {
vehiclesRented[i] = vehiclesRented[currentRentedCount - 1];
vehiclesRented[currentRentedCount - 1] = null;
currentRentedCount--;
break;
}
}
}
public double calculateRent(int days) {
double totalCost = 0;
for (int i = 0; i < currentRentedCount; i++) {
totalCost += vehiclesRented[i].getRentalRatePerDay() * days;
}
return totalCost;
}
public int countVehiclesByType(String type) {
int count = 0;
for (int i = 0; i < currentRentedCount; i++) {
if (vehiclesRented[i].getType().equalsIgnoreCase(type)) {
count++;
}
}
return count;
}
public void printInfo() {
System.out.println("Customer Information:");
System.out.println("Name: " + name);
System.out.println("ID: " + id);
System.out.println("License Number: " + licenseNumber);
System.out.println("Vehicles Rented: ");
for (int i = 0; i < currentRentedCount; i++) {
vehiclesRented[i].printInfo();
}
}
}