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
42
43
44
45
46
47
48
49
50
51
52
53
54
package agency;
import util.TimeProvider;
public abstract class AbstractVehicle implements Vehicle {
protected String brand;
protected String model;
protected int productionYear;
protected static final int MINIMAL_YEAR_VALUE = 1900;
public AbstractVehicle(String brand, String model, int productionYear) {
int currentYear = TimeProvider.currentYearValue();
if (productionYear < MINIMAL_YEAR_VALUE || productionYear > currentYear) {
throw new IllegalArgumentException("Invalid production year: " + productionYear);
}
this.brand = brand;
this.model = model;
this.productionYear = productionYear;
}
@Override
public String getBrand() {
return brand;
}
@Override
public String getModel() {
return model;
}
@Override
public int getProductionYear() {
return productionYear;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
AbstractVehicle that = (AbstractVehicle) o;
return productionYear == that.productionYear &&
brand.equals(that.brand) &&
model.equals(that.model);
}
@Override
public abstract String toString();
@Override
public abstract double dailyRentalPrice();
}