This commit is contained in:
EngOsamah 2020-12-02 13:52:11 +03:00
parent 6dbe6a331f
commit 2f14faa2eb
2 changed files with 77 additions and 3 deletions

View File

@ -92,6 +92,10 @@ public class MakkahCity {
for (Vehicle vehicle : listOfVehicles) {
vehicle.setCurrentStreet(null);
}
Vehicle.resetMaxArrived();
Vehicle.resetMinArrived();
addCivilVehicleNoise();
System.out.println("***************STARTING LAST DAY***************");
while(!lastDayTimeMan.isEnded()) {
checkInput();
@ -548,10 +552,19 @@ public class MakkahCity {
s.append(String.format(fFormat,"Arafat",allArrivedToArafatTime)).append("\n");
if (arr && allArrivedToHotelsTime != null)
s.append(String.format(fFormat,"Hotels",allArrivedToHotelsTime)).append("\n");
s.append(String.format("Buses: %d, Buses done: %d\nBuses arrived in the last hour: %d, Average trip in last hour: %s\n",
numberOfBusses, numberOfArrivedBuses, getNumberOfArrivedBussesPerHour(), avgTimeOfTrip()));
s.append(String.format("Buses: %d, Buses done: %d %s\nBuses arrived in the last hour: %d, Average trip in last hour: %s\n",
numberOfBusses, numberOfArrivedBuses, minMaxRep() , getNumberOfArrivedBussesPerHour(), avgTimeOfTrip()));
return s.toString();
}
private static String minMaxRep() {
StringBuilder report = new StringBuilder();
if (Vehicle.getMaxArrived() != null && Vehicle.getMinArrived() != null) {
report.append(String.format(" maximum trip %s", Vehicle.getMaxArrived().timeToString()));
report.append(String.format(" minimum trip %s", Vehicle.getMinArrived().timeToString()));
}
return report.toString();
}
/**
* Calculate average trip time for last 10 minutes
@ -617,7 +630,7 @@ public class MakkahCity {
}
}
return num;
}
}//???
private static int getNumberOfArrivedBussesPerHour() {
Calendar now = currenttimeManager.getCurrentCalendar();

View File

@ -13,6 +13,8 @@ public abstract class Vehicle {
private Date timeStartedMoving;
private Date timeOfArrival;
private Date timeStartedOnCurrentStreet;
private static Vehicle max;
private static Vehicle min;
//Map Street to Minutes
private HashMap<Street, Integer> routeTimeHistory = new HashMap<>();
@ -38,8 +40,67 @@ public abstract class Vehicle {
setTimeOfArrival(MakkahCity.getTimeMan().getCurrentTime());
getCurrentStreet().getVehicles().remove(this);
this.currentLocation = 0;
maxArrived();
minArrived();
}
public void maxArrived() {
if (this instanceof Bus) {
if (max == null)
max = this;
else {
long thisMinutes = (getTimeOfArrival().getTime() - getTimeStartedMoving().getTime())/60000;
long maxMinutes = (max.getTimeOfArrival().getTime() - max.getTimeStartedMoving().getTime())/60000;
if (thisMinutes > maxMinutes)
max = this;
}
}
}
public void minArrived() {
if (this instanceof Bus) {
if (min == null)
min = this;
else {
long thisMinutes = (getTimeOfArrival().getTime() - getTimeStartedMoving().getTime())/60000;
long maxMinutes = (min.getTimeOfArrival().getTime() - min.getTimeStartedMoving().getTime())/60000;
if (thisMinutes < maxMinutes)
min = this;
}
}
}
public String timeToString() {
if (this == null)
return "null";
else {
long minutes = (getTimeOfArrival().getTime() - getTimeStartedMoving().getTime())/60000;
int hours =(int) minutes / 60;
minutes %= 60;
return String.format("%2d:%02d", hours,minutes);}
}
public static Vehicle getMaxArrived() {
return max;
}
public static Vehicle getMinArrived() {
return min;
}
public static void resetMaxArrived() {
Vehicle.max = null;
}
public static void resetMinArrived() {
Vehicle.min = null;
}
public void move(double distance) {
if (!isMoving()) {
setMoving(true);