-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVan.java
More file actions
114 lines (100 loc) · 3.8 KB
/
Van.java
File metadata and controls
114 lines (100 loc) · 3.8 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
/**
* Class to save all the van details
* This class contains all the calculations and details of the van
* It extends Vehicle so it has all the features of a vehicle
*/
class Van extends Vehicle{
private double rate=235;
private double lateFee=299;
//Constructor to accept van details
Van(String vehicleId,int year,String make,String model,int status,VehicleType vehicleType)
{
super(vehicleId,year,make,model,status,vehicleType);
this.rate=rate;
}
/**
* Used to add either cars or vans to the list
* @param endDate,startDate accepts start date and end date
* @return lateFee the late fee
*/
public double getLateFee(DateTime endDate,DateTime startDate){
if(DateTime.diffDays(endDate,startDate)>0)
return this.lateFee* DateTime.diffDays(endDate,startDate);
else
return this.lateFee=0.0;
}
/**
* Used to add either cars or vans to the list
* @param returnDate accepts the date as ro when it has to be returned
* @return Returns true if returned else false with appropriate messages
*/
public boolean returnVehicle(DateTime returnDate)
{
String vehicleType;
if(this.Vehicle_id.contains("C_"))
vehicleType="car";
else
vehicleType="van";
if(this.vehicleStatus!=0)
{
DateTime estimatedDate= this.records[this.getLastElementIndex()].getEstimatedReturnDate();
DateTime rentDate= this.records[this.getLastElementIndex()].getRentDate();
if (vehicleType.equals("van") && DateTime.diffDays(returnDate,rentDate)<1){
return false;
}
else{
double rent=this.rate* DateTime.diffDays(returnDate,this.records[this.getLastElementIndex()].getRentDate()) ;
this.records[this.getLastElementIndex()].setData(returnDate,rent,this.getLateFee(returnDate,estimatedDate));
this.vehicleStatus=0;
return true;
}}else return false;
}
/**
* Used to add either cars or vans to the list
* @param completionDate accepts the date as ro when it has to be maintained
* @return Returns true if returned else false with appropriate messages
*/
public boolean completeMaintenance(DateTime completionDate)
{
if(this.vehicleStatus!=2 && DateTime.diffDays(completionDate,this.vehicleType.getLastMaintenance())<12)
return false;
this.vehicleType.setLastMaintenance(completionDate);
this.vehicleStatus=0;
return true;
}
/**
* Method used to get details of van
*/
public String toString()
{
String details = super.toString();
DateTime lastMaintenanceDate= this.vehicleType.getLastMaintenance();
details += ":"+ lastMaintenanceDate.toString();
return details;
}
/**
* Method used to get details of van with their rental history
* Prints the rental record of van
*/
public String getDetails()
{
String details =super.getDetails();
details+= "\nLast maintenance date:\t"+(this.vehicleType.getLastMaintenance()).toString();
if(this.records[0]==null)
details+="\nRENTAL RECORD:\tempty";
else{
details+="\nRENTAL RECORD:\n";
int count=0;
for(int index=0;this.records[index]!=null;index++)
count++;
for(int index=count-1;index>=0;index--)
{
details+= this.records[index].getDetails()+" \n";
for(int innerIndex=0;innerIndex<10;innerIndex++)
details+= "-";
details+= " \n";
}
}
return details;
}
}