Add ref to street in every Accident
Add Street Object for Accident as location for Instances of Accident. Removed 'isInAccident()' from 'Breakable' interface The idea is from Previous suggested UML that replaces Broken and Accident with getStatus() that gives info about Breakable object. isBroken() now returns 1 if its eaither in Accident or Broken. Can check getCurrentAccident() for null. Signed-off-by: HeshamTB <hishaminv@gmail.com> Signed-off-by: HeshamTB <hishaminv@gmail.com>
This commit is contained in:
parent
8a4a7d8f29
commit
f8b5e79187
@ -4,11 +4,12 @@ public class Accident {
|
||||
|
||||
private Date date;
|
||||
private Breakable[] involvedCars;
|
||||
//private Street street;
|
||||
private Street location;
|
||||
|
||||
public Accident(Date date, Breakable[] involvedCars) {
|
||||
public Accident(Date date, Breakable[] involvedCars, Street location) {
|
||||
setDate(date);
|
||||
setInvovledCars(involvedCars);
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
private void setDate(Date date){
|
||||
@ -29,6 +30,10 @@ public class Accident {
|
||||
return involvedCars;
|
||||
}
|
||||
|
||||
public Street getLocation(){
|
||||
return this.location;
|
||||
}
|
||||
|
||||
public int getTimeToFix(){
|
||||
int max = 0;
|
||||
for (Breakable car : involvedCars){
|
||||
|
@ -4,8 +4,7 @@ public interface Breakable {
|
||||
|
||||
int getTimeToFix();
|
||||
boolean isBroken();
|
||||
boolean isInAccident();
|
||||
Accident collide(Breakable car, Date time);
|
||||
Accident collide(Breakable car, Date time, Street location);
|
||||
void _break(Date time);
|
||||
void fix();
|
||||
|
||||
|
@ -3,7 +3,6 @@ import java.util.Date;
|
||||
public abstract class CivilVehicle extends Vehicle implements Breakable {
|
||||
|
||||
private boolean broken;
|
||||
private boolean inAccident;
|
||||
private Accident currentAccident;
|
||||
private Date breakDownTime;
|
||||
|
||||
@ -17,19 +16,15 @@ public abstract class CivilVehicle extends Vehicle implements Breakable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInAccident() {
|
||||
return inAccident;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Accident collide(Breakable car, Date time) {
|
||||
public Accident collide(Breakable car, Date time, Street location) {
|
||||
if (currentAccident == null) {
|
||||
Breakable[] cars = new Breakable[2];
|
||||
cars[0] = this;
|
||||
cars[1] = car;
|
||||
Accident accident = new Accident(time, cars);
|
||||
Accident accident = new Accident(time, cars, location);
|
||||
this.currentAccident = accident;
|
||||
this.inAccident = true;
|
||||
if (car instanceof CivilVehicle)
|
||||
((CivilVehicle)car).setCurrentAccident(accident);
|
||||
return accident;
|
||||
}
|
||||
return null;
|
||||
@ -38,21 +33,24 @@ public abstract class CivilVehicle extends Vehicle implements Breakable {
|
||||
@Override
|
||||
public void _break(Date time) {
|
||||
broken = true;
|
||||
breakDownTime = time;
|
||||
this.breakDownTime = time;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fix() {
|
||||
broken = false;
|
||||
inAccident = false;
|
||||
breakDownTime = null;
|
||||
this.currentAccident = null;
|
||||
}
|
||||
|
||||
public Date getBreakDownTime() {
|
||||
return breakDownTime;
|
||||
}
|
||||
|
||||
public Accident getCurrentAccident() {
|
||||
return currentAccident;
|
||||
}
|
||||
|
||||
public Date getBreakDownTime() {
|
||||
return breakDownTime;
|
||||
public void setCurrentAccident(Accident accident){
|
||||
if (accident != null) this.currentAccident = accident;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user