-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCarToRent.java
More file actions
executable file
·165 lines (145 loc) · 5.05 KB
/
CarToRent.java
File metadata and controls
executable file
·165 lines (145 loc) · 5.05 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
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
import javax.swing.JOptionPane;
/**
* class CarToRent,subclass of Car
* it is about renting cars
*/
public class CarToRent extends Car
{
//variables rental date, return date, admin fee, number of days, daily rate, total accumulated and on loan
private String rentalDate, returnDate;
private int adminFee, nOfDays, dailyRate, totalAccum;
private boolean onLoan;
public CarToRent(String theCarDesc, int fee, int rate)
{
//initializing and fetching car's description from superclass Car
super(theCarDesc);
adminFee = fee;
dailyRate = rate;
rentalDate = "";
returnDate = "";
nOfDays = 0;
totalAccum = 0;
}
public String getRentalDate()
{
//accessor method for the car's Rental Date
return rentalDate;
}
public String getReturnDate()
{
//accessor method for the car's Return Date
return returnDate;
}
public int getAdminFee()
{
//accessor method for the Admin Fees
return adminFee;
}
public int getNumberOfDays()
{
//accessor method for the Number of days the car will be rented
return nOfDays;
}
public int getDailyRate()
{
//accessor method for the Daily Rate
return dailyRate;
}
public int getTotalAccumulated()
{
//accessor method for Total Money Accumulated
return totalAccum;
}
public boolean getLoanStatus()
{
//accessor method for Loan Status
return onLoan;
}
public void setDailyRate(int dailyRate)
{
////mutator method for chaning the Daily Rates on demand
System.out.println("Daily Rate successfully changed!");
}
public void setAdminFees(int adminFee)
{
//mutator method for chaning the Admin fees on demand
System.out.println("Admin fees successfully changed!");
}
public void rentCar(String name, String rentDate, String retuDate, int days)
{
//if car is on load this method will exit fast without making any other checks or changes
if(onLoan == true){
JOptionPane.showInternalMessageDialog(null, "This car is already on loan, unavailable until " +returnDate,
"WARNING!", JOptionPane.WARNING_MESSAGE);
return;
}
//calling changeCustName method from superclass Car
changeCustName(name);
//taken from user input
rentalDate = rentDate;
returnDate = retuDate;
nOfDays = days;
//changing loan status
onLoan = true;
//multiplying the daily rate by the number of days and then adding the admin fee
totalAccum = dailyRate * nOfDays + adminFee;
JOptionPane.showInternalMessageDialog(null, "Car is Rent to: " +custName,
"Success", JOptionPane.INFORMATION_MESSAGE);
}
public void carReturn()
{
//checking now the on loan status since if its not needed the method will exit instead of doing if/\else...
if(onLoan == false){
JOptionPane.showInternalMessageDialog(null, "This Car is not on loan",
"WARNING!", JOptionPane.WARNING_MESSAGE);
return;
}
//reinitializing the parameters since car is not on loan
changeCustName("");
nOfDays = 0;
rentalDate = "dd/MM/yyyy";
returnDate = "dd/MM/yyyy";
onLoan = false;
}
public void getDescNTotal()
{
//displays the car description and money accumulated, also cleaning terminal
System.out.println("\f");
System.out.println("Car's Description: \t " +getCarDesc());
System.out.println("Total Accumulated Money: " +totalAccum+ "£");
}
public void displayCarDetails()
{
//cleaning the console for readability and showing everything organised
displayInfo();
System.out.println("The Daily Rate is: " +dailyRate+ "£");
System.out.println("The Admin Fee is : " +adminFee+ "£");
if(onLoan == true){
System.out.println("The Rental Date started from: " +rentalDate);
System.out.println("The Return date is due on: " +returnDate);
System.out.println("The number of days this car was rented is:" +nOfDays+ "days");
}
}
//giving the display option proper format for the CarToRent Objects
@Override
public String toString() {
if(custName == "" || rentalDate == "dd/MM/yyyy" || returnDate == "dd/MM/yyyy")
{
return ("\nCar Number: "+ this.carNumber+
"\nDescription: "+this.carDesc+
"\nFee: "+ this.adminFee +
"\nDaily rate: "+ this.dailyRate);
}
else
{
return ("\nCar Number: "+ this.carNumber+
"\nDescription: "+this.carDesc+
"\nCustomer's Name:" +this.custName+
"\nFee: "+ this.adminFee +
"\nDaily rate: "+ this.dailyRate +
"\nRental Date: "+ this.rentalDate+
"\nReturn Date: "+ this.returnDate+
"\nNumber of Days: "+this.nOfDays);
}
}
}