-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVehicleType.java
More file actions
118 lines (107 loc) · 3.02 KB
/
VehicleType.java
File metadata and controls
118 lines (107 loc) · 3.02 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
/**
* This class has the type of vehicle whether it is a car or van
* it has several methods for checking whether the car r van could be rented or not
*/
class VehicleType {
private int carSeats;
private int vanSeats=15;
private DateTime LastMaintenance;
private String[] days = {"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
//Constructor of Car type
VehicleType(int seats)
{
this.carSeats=seats;
}
//Constructor for Van type
VehicleType(int seats,DateTime LastMaintenance){
this.vanSeats=seats;
this.LastMaintenance=LastMaintenance;
}
/**
* @param type
* method to get seats of vehicle by accepting type of vehicle
*/
public int getSeats(String type)
{
if(type.equals("car")){
return this.carSeats;
}
else{
return this.vanSeats;
}
}
/**
* method to get seats of vehicle
*/
public int getCarSeats()
{
return this.carSeats;
}
/**
* method to set seats of vehicle by accepting seats
*/
public void setCarSeats(int seats)
{
this.carSeats=seats;
}
/**
* method to get index from the days array
*/
private int indexOf(String day){
for(int index=0;index<days.length;index++)
if(days[index].equals(day))
return index;
return -1;
}
/**
* method to get Last Maintenance
*/
public DateTime getLastMaintenance(){
return this.LastMaintenance;
}
/**
* method to set Last Maintenance
*/
public void setLastMaintenance(DateTime date)
{
this.LastMaintenance=date;
}
/**
* @param date,type
* checking which day the vehicle is being rented and setting minimum days it can be rented
* method to check whether a vehicle can be rented for a specific number of days
*/
public int canBeRentedForMinimumDays(DateTime date,String type)
{
if(this.indexOf(date.getNameOfDay())+1<=5 && this.indexOf(date.getNameOfDay())+1>=1 && type.equals("car")){
return 2;
}
else if(type.equals("car")){
return 3;
}
else{
return 1; //van can be rented only 1 day
}
}
/**
* @param rentDate,type,numOfRentDays
* method to check whether a vehicle is under maintenance or not
* @return true or false based on the input
*/
public boolean IsUnderMaintenance(DateTime rentDate,String type,int numOfRentDays)
{
DateTime nextMaintenance=new DateTime(this.LastMaintenance,12);
if(type.equals("van") && DateTime.diffDays(nextMaintenance,new DateTime(rentDate,numOfRentDays))>=0 && numOfRentDays<=12)
{
return false;
}
if(type.equals("car"))
{
return false;
}
else
{
return true;
}
}
}