2020-10-16 05:52:46 +02:00
|
|
|
import java.util.Date;
|
|
|
|
|
|
|
|
public class Accident {
|
|
|
|
|
|
|
|
private Date date;
|
|
|
|
private Breakable[] involvedCars;
|
2020-11-06 19:55:01 +01:00
|
|
|
private Street location;
|
2020-10-16 05:52:46 +02:00
|
|
|
|
2020-11-06 19:55:01 +01:00
|
|
|
public Accident(Date date, Breakable[] involvedCars, Street location) {
|
2020-10-16 05:52:46 +02:00
|
|
|
setDate(date);
|
|
|
|
setInvovledCars(involvedCars);
|
2020-11-06 19:55:01 +01:00
|
|
|
this.location = location;
|
2020-10-16 05:52:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void setDate(Date date){
|
2020-10-27 06:57:13 +01:00
|
|
|
this.date = date;
|
2020-10-16 05:52:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void setInvovledCars(Breakable[] cars){
|
|
|
|
if (cars.length > 1) this.involvedCars = cars;
|
|
|
|
else throw new IllegalArgumentException("Can not make an accident with one car");
|
|
|
|
}
|
|
|
|
|
|
|
|
public Date getDate() {
|
|
|
|
return date;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Breakable[] getInvolvedCars() {
|
|
|
|
return involvedCars;
|
|
|
|
}
|
|
|
|
|
2020-11-06 19:55:01 +01:00
|
|
|
public Street getLocation(){
|
|
|
|
return this.location;
|
|
|
|
}
|
|
|
|
|
2020-10-16 05:52:46 +02:00
|
|
|
public int getTimeToFix(){
|
|
|
|
int max = 0;
|
|
|
|
for (Breakable car : involvedCars){
|
|
|
|
if (car.getTimeToFix() > max) max = car.getTimeToFix();
|
|
|
|
}
|
|
|
|
return max;
|
|
|
|
}
|
2020-11-07 10:33:01 +01:00
|
|
|
|
|
|
|
public boolean isDone(){
|
|
|
|
for (Breakable car : this.involvedCars){
|
|
|
|
/*
|
|
|
|
if broken flag is set and currAcc is ref to this instance
|
|
|
|
then the accident is not done.
|
|
|
|
The ref to accident should be null if fix() of car is invoked
|
|
|
|
*/
|
|
|
|
if (car.isBroken() &&
|
|
|
|
((CivilVehicle)car).getCurrentAccident() == this) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2020-10-16 05:52:46 +02:00
|
|
|
}
|