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 Date date;
|
||||||
private Breakable[] involvedCars;
|
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);
|
setDate(date);
|
||||||
setInvovledCars(involvedCars);
|
setInvovledCars(involvedCars);
|
||||||
|
this.location = location;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setDate(Date date){
|
private void setDate(Date date){
|
||||||
@ -29,6 +30,10 @@ public class Accident {
|
|||||||
return involvedCars;
|
return involvedCars;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Street getLocation(){
|
||||||
|
return this.location;
|
||||||
|
}
|
||||||
|
|
||||||
public int getTimeToFix(){
|
public int getTimeToFix(){
|
||||||
int max = 0;
|
int max = 0;
|
||||||
for (Breakable car : involvedCars){
|
for (Breakable car : involvedCars){
|
||||||
|
@ -4,8 +4,7 @@ public interface Breakable {
|
|||||||
|
|
||||||
int getTimeToFix();
|
int getTimeToFix();
|
||||||
boolean isBroken();
|
boolean isBroken();
|
||||||
boolean isInAccident();
|
Accident collide(Breakable car, Date time, Street location);
|
||||||
Accident collide(Breakable car, Date time);
|
|
||||||
void _break(Date time);
|
void _break(Date time);
|
||||||
void fix();
|
void fix();
|
||||||
|
|
||||||
|
@ -3,7 +3,6 @@ import java.util.Date;
|
|||||||
public abstract class CivilVehicle extends Vehicle implements Breakable {
|
public abstract class CivilVehicle extends Vehicle implements Breakable {
|
||||||
|
|
||||||
private boolean broken;
|
private boolean broken;
|
||||||
private boolean inAccident;
|
|
||||||
private Accident currentAccident;
|
private Accident currentAccident;
|
||||||
private Date breakDownTime;
|
private Date breakDownTime;
|
||||||
|
|
||||||
@ -17,19 +16,15 @@ public abstract class CivilVehicle extends Vehicle implements Breakable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isInAccident() {
|
public Accident collide(Breakable car, Date time, Street location) {
|
||||||
return inAccident;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Accident collide(Breakable car, Date time) {
|
|
||||||
if (currentAccident == null) {
|
if (currentAccident == null) {
|
||||||
Breakable[] cars = new Breakable[2];
|
Breakable[] cars = new Breakable[2];
|
||||||
cars[0] = this;
|
cars[0] = this;
|
||||||
cars[1] = car;
|
cars[1] = car;
|
||||||
Accident accident = new Accident(time, cars);
|
Accident accident = new Accident(time, cars, location);
|
||||||
this.currentAccident = accident;
|
this.currentAccident = accident;
|
||||||
this.inAccident = true;
|
if (car instanceof CivilVehicle)
|
||||||
|
((CivilVehicle)car).setCurrentAccident(accident);
|
||||||
return accident;
|
return accident;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@ -38,21 +33,24 @@ public abstract class CivilVehicle extends Vehicle implements Breakable {
|
|||||||
@Override
|
@Override
|
||||||
public void _break(Date time) {
|
public void _break(Date time) {
|
||||||
broken = true;
|
broken = true;
|
||||||
breakDownTime = time;
|
this.breakDownTime = time;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void fix() {
|
public void fix() {
|
||||||
broken = false;
|
broken = false;
|
||||||
inAccident = false;
|
this.currentAccident = null;
|
||||||
breakDownTime = null;
|
}
|
||||||
|
|
||||||
|
public Date getBreakDownTime() {
|
||||||
|
return breakDownTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Accident getCurrentAccident() {
|
public Accident getCurrentAccident() {
|
||||||
return currentAccident;
|
return currentAccident;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Date getBreakDownTime() {
|
public void setCurrentAccident(Accident accident){
|
||||||
return breakDownTime;
|
if (accident != null) this.currentAccident = accident;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user