Add ref to Camp in Bus ...

- Ref to Camp in Bus.
	- Override arrive() in bus to
	notify camp.
	- isAllArrived() changed to implement camp.isDone().
	Should be a bit faster

Signed-off-by: HeshamTB <hishaminv@gmail.com>
This commit is contained in:
HeshamTB 2020-11-15 17:02:56 +03:00
parent f6209c669d
commit d5891ad2d1
3 changed files with 31 additions and 4 deletions

View File

@ -2,6 +2,7 @@
public class Bus extends CivilVehicle {
private String UID;
private Campaign campaign;
private static int numeberOfBuses;
private final int TIME_TO_FIX = 20; //in minutes
public static final int MAX_FORWARD = 900; //Meter/Min
@ -13,6 +14,12 @@ public class Bus extends CivilVehicle {
generateUID();
}
@Override
public void arrive() {
super.arrive();
campaign.busArived(this);
}
@Override
public int getTimeToFix() {
return TIME_TO_FIX;
@ -26,4 +33,12 @@ public class Bus extends CivilVehicle {
public String getUID(){
return this.UID;
}
public Campaign getCampaign() {
return campaign;
}
public void setCampaign(Campaign campaign) {
this.campaign = campaign;
}
}

View File

@ -4,6 +4,7 @@ import java.util.Date;
public class Campaign {
private String UID;
private int numberOfAriivedBuses;
//private int housingNumber;
//private String name;
private District hotelDistrict;
@ -30,6 +31,16 @@ public class Campaign {
generateUID();
}
public void busArived(Bus bus) {
if(numberOfAriivedBuses < vehicles.size())
numberOfAriivedBuses++;
//Check if it is in list before increment?
}
public boolean isDone() {
return numberOfAriivedBuses == vehicles.size();
}
public Route getHousingToDestRoute() {
return housingToDestRoute;
}
@ -90,7 +101,9 @@ public class Campaign {
private void generateBusses(int number){
for (int i = 1; i <= number; i++) {
vehicles.add(new Bus());
Bus bus = new Bus();
vehicles.add(bus);
bus.setCampaign(this);
}
}

View File

@ -371,9 +371,8 @@ public class MakkahCity {
private static boolean isAllArrived() {
for (Campaign campaign : listOfCampaigns)
for (Vehicle vehicle : campaign.getVehicles())
if (!vehicle.isArrivedToDest())
return false;
if (!campaign.isDone())
return false;
return true;
}