Newer
Older
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
package agency;
import util.TimeProvider;
public class CarSpecifics implements VehiclesSpecifics {
private int numberOfSeats;
private int productionYear;
private static final int PRICE_PER_SEAT_FOR_OLD_CAR = 20;
private static final int PRICE_PER_SEAT_FOR_NEW_CAR = 40;
public CarSpecifics(int numberOfSeats, int productionYear) {
if (numberOfSeats < 1) {
throw new IllegalArgumentException("Invalid number of seats: " + numberOfSeats);
}
this.numberOfSeats = numberOfSeats;
this.productionYear = productionYear;
}
public int getNumberOfSeats() {
return numberOfSeats;
}
public int getProductionYear() {
return productionYear;
}
boolean isNew() {
int currentYear = TimeProvider.currentYearValue();
return (currentYear - productionYear) <= 5;
}
@Override
public double calculateDailyRentalPrice() {
return numberOfSeats * (isNew() ? PRICE_PER_SEAT_FOR_NEW_CAR : PRICE_PER_SEAT_FOR_OLD_CAR);
}
@Override
public String getDetails() {
return (numberOfSeats > 1 ? numberOfSeats + " seats" : "1 seat");
}
}