-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustomer.java
More file actions
86 lines (70 loc) · 2.22 KB
/
Customer.java
File metadata and controls
86 lines (70 loc) · 2.22 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
import java.util.HashMap;
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
/**
*
* @author kübra
*/
public class Customer {
private String name;
private int age;
private String customerId;
HashMap<Vehicle, Integer> rentedVehicles = new HashMap<>();
public Customer(String name, int age, String customerId) {
this.name = name;
this.age = age;
this.customerId = customerId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getCustomerId() {
return customerId;
}
public void setCustomerId(String customerId) {
this.customerId = customerId;
}
public void rentVehicle(Vehicle v, int days) {
if (age > 18 && v.getIsAvailable()) {
rentedVehicles.put(v, days);
v.setIsAvailable(false);
System.out.println(v.getBrand() + " " + "rented successfully");
} else {
if (age <= 18) {
System.out.println("Renting is unsuccessfull age is invalid");
}
if (v.getIsAvailable() == false) {
System.out.println("Renting is unsuccessfull vehicle is not available");
}
}
}
public void returnVehicle(Vehicle v) {
v.setIsAvailable(true);
rentedVehicles.remove(v);
System.out.println(v.getBrand() + " " + "is returned successfully");
}
public void calculateTotalRent() {
double totalRent = 0;
for (Vehicle v : rentedVehicles.keySet()) {
totalRent += v.calculateRent(rentedVehicles.get(v));
}
System.out.println("Total rent is: " + totalRent);
}
public void displayRentedVehicles() {
for (Vehicle v : rentedVehicles.keySet()) {
v.displayInfo();
System.out.println("\n");
}
}
}