-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCarToRent.java
196 lines (179 loc) · 4.97 KB
/
CarToRent.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
/**
* CarToRent is a subclass of the parent class Car.
*
* @author 16033148, Keyur Khadka
* @version 29th December 2016
*/
import javax.swing.JFrame;
import javax.swing.JOptionPane;
public class CarToRent extends Car
{
private String rentalDate;
private String returnDate;
private int adminFee;
private int numberOfDays;
private int dailyRate;
private int totalAccumulated;
private boolean onLoan;
private JFrame frame;
/**
* Constructor with three parameters.
*/
public CarToRent(String description, int adminFee, int dailyRate)
{
super(description);
this.adminFee = adminFee;
this.dailyRate = dailyRate;
rentalDate = "";
returnDate = "";
numberOfDays = 0;
totalAccumulated = 0;
onLoan = false;
}
/**
* Getter/Accessor (method)
* Method: getRentalDate
* Return type: String
* Access modifier: public
*/
public String getRentalDate()
{
return rentalDate;
}
/**
* Getter/Accessor (method)
* Method: getReturnDate
* Return type: String
* Access modifier: public
*/
public String getReturnDate()
{
return returnDate;
}
/**
* Getter/Accessor (method)
* Method: getAdminFee
* Return type: int
* Access modifier: public
*/
public int getAdminFee()
{
return adminFee;
}
/**
* Getter/Accessor (method)
* Method: getNumberOfDays
* Return type: int
* Access modifier: public
*/
public int getNumberOfDays()
{
return numberOfDays;
}
/**
* Getter/Accessor (method)
* Method: getDailyRate
* Return type: int
* Access modifier: public
*/
public int getDailyRate()
{
return dailyRate;
}
/**
* Getter/Accessor (method)
* Method: getTotalAccumulated
* Return type: int
* Access modifier: public
*/
public int getTotalAccumulated()
{
return totalAccumulated;
}
/**
* Getter/Accessor (method)
* Method: getOnLoan
* Return type: boolean
* Access modifier: public
*/
public boolean isOnLoan()
{
return onLoan;
}
/**
* Setter/Mutator (method)
* Method: setDailyRate
* Parameter: dailyRate of type int
* Return type: void
* Access modifier: public
*/
public void setDailyRate(int dailyRate)
{
this.dailyRate = dailyRate;
}
/**
* Setter/Mutator (method)
* Method: setAdminFee
* Parameter: adminFee of type int
* Return type: void
* Access modifier: public
*/
public void setAdminFee(int adminFee)
{
this.adminFee = adminFee;
}
/**
* Method to rent the car with three parameters.
*/
public void rentCar(String customersName, String rentalDate, String returnDate, int numberOfDays)
{
if (onLoan == true) {
JOptionPane.showMessageDialog(frame, "The car has already been rented", "Sorry", JOptionPane.ERROR_MESSAGE);
}
else {
super.setCustomersName(customersName);
this.rentalDate = rentalDate;
this.returnDate = returnDate;
this.numberOfDays = numberOfDays;
onLoan = true;
totalAccumulated = totalAccumulated + ((dailyRate * numberOfDays) + adminFee);
JOptionPane.showMessageDialog(frame, "Car has been successfully rented", "Car Rented", JOptionPane.INFORMATION_MESSAGE);
}
}
/**
* Method to return the car.
*/
public void returnCar()
{
if(onLoan == true) {
super.setCustomersName("");
numberOfDays = 0;
rentalDate = "";
returnDate = "";
onLoan = false;
JOptionPane.showMessageDialog(frame, "Car has been successfully returned", "Car Returned", JOptionPane.INFORMATION_MESSAGE);
}
else {
JOptionPane.showMessageDialog(frame, "You cannot return the car because you have not rented the car yet.", "Sorry", JOptionPane.ERROR_MESSAGE);
}
}
/**
* Method to print the description and total accumulated.
*/
public void printDescription()
{
System.out.println(super.getDescription() + "\nTotal Accumulated = " +totalAccumulated);
}
/**
* Method to display the details of the car.
*/
public void display()
{
super.display();
System.out.println("Admin fee: " +adminFee+ "\nDaily rate: " +dailyRate);
if(onLoan == true) {
System.out.println("Rental Date: " +rentalDate+ "\nReturn Date: " +returnDate+ "\nNumber of days: " +numberOfDays);
}
System.out.println("\n");
}
}