Compare commits

...

5 Commits

Author SHA1 Message Date
20cfeb268c Amend prev commit about checks 2021-01-11 02:37:28 +03:00
200c06bfac Skip done vehicles:
Skip done cars improves perf greatly.
    Tested in parallel with previous commit
    and results in faster exc when sim has more/less
    generated cars.
2021-01-11 01:53:31 +03:00
7ffbe689bc Discard special cases for general implementation:
Instead of checking instance of veh,
    use the abstract method getMaxSpeed()
    with a given factor.

    This should reduce redundant checks
    (Wasted CPU cycles). Thus, run is
    a tiny bit faster.
2021-01-10 23:48:22 +03:00
612c00a3f1 Reindent (No Change) 2021-01-10 22:00:25 +03:00
69c1a19ed9 Memory usage improvements:
- Use smaller number types int -> short
    saves in heap size.

    - Save UID of vehicles as int (4 Bytes)
    or short (2 Bytes) and when needed, make
    a String as UID. A string would take up
    (16 Bytes).
2021-01-10 21:57:51 +03:00
7 changed files with 187 additions and 198 deletions

View File

@ -1,11 +1,11 @@
public class Bus extends CivilVehicle { public class Bus extends CivilVehicle {
private String UID; private int UID;
private Campaign campaign; private Campaign campaign;
private static int numeberOfBuses; private static int numeberOfBuses;
private final int TIME_TO_FIX = 20; //in minutes private final short TIME_TO_FIX = 20; //in minutes
public static final int MAX_FORWARD = 900; //Meter/Min public static final short MAX_FORWARD = 900; //Meter/Min
public static final double STD_BUS_SIZE = 10; public static final double STD_BUS_SIZE = 10;
@ -40,11 +40,11 @@ public class Bus extends CivilVehicle {
private void generateUID() { private void generateUID() {
numeberOfBuses++; numeberOfBuses++;
this.UID = String.format("BUS%04d", numeberOfBuses); this.UID = numeberOfBuses;
} }
public String getUID(){ public String getUID(){
return this.UID; return String.format("BUS%04d", UID);
} }
public Campaign getCampaign() { public Campaign getCampaign() {

View File

@ -467,7 +467,6 @@ public class GUI_History {
} }
public String avgTimeOfTrip() { public String avgTimeOfTrip() {
//TODO: does output diff value even after all have arrived.
Calendar now = new GregorianCalendar(); Calendar now = new GregorianCalendar();
now.setTime(currenttimeManager); now.setTime(currenttimeManager);
Calendar from = (GregorianCalendar)now.clone(); Calendar from = (GregorianCalendar)now.clone();

View File

@ -251,7 +251,7 @@ public class GUI_ViewStreet {
if (vehicles.isEmpty()) return; if (vehicles.isEmpty()) return;
vehicleData = new Object[vehicles.size()][6]; vehicleData = new Object[vehicles.size()][6];
for (int i = 0; i < vehicles.size(); i++) { for (int i = 0; i < vehicles.size(); i++) {
vehicleData[i][0] = vehicles.get(i).getUID();// TODO: There is an Exception error here; vehicleData[i][0] = vehicles.get(i).getUID();
if (vehicles.get(i) instanceof Bus) if (vehicles.get(i) instanceof Bus)
vehicleData[i][1] = ((Bus)vehicles.get(i)).getCampaign().getHotelDistrict().name(); vehicleData[i][1] = ((Bus)vehicles.get(i)).getCampaign().getHotelDistrict().name();
else vehicleData[i][1] = "Local Vehicle"; else vehicleData[i][1] = "Local Vehicle";

View File

@ -17,8 +17,8 @@ public class MakkahCity {
private static Date allArrivedToHotelsTime; private static Date allArrivedToHotelsTime;
private static final PDate firstDayTimeMan = new PDate( private static final PDate firstDayTimeMan = new PDate(
new GregorianCalendar(1442, Calendar.JANUARY, 9, 4, 0, 0), new GregorianCalendar(1442, Calendar.JANUARY, 9, 4, 0, 0),
new GregorianCalendar(1442, Calendar.JANUARY, 9, 18, 0, 0) new GregorianCalendar(1442, Calendar.JANUARY, 9, 18, 0, 0)
); );
private static final PDate lastDayTimeMan = new PDate( private static final PDate lastDayTimeMan = new PDate(
@ -46,9 +46,9 @@ public class MakkahCity {
private static JLabel lblNumOfDonebuses; private static JLabel lblNumOfDonebuses;
private static JLabel lblMaximumTripValue; private static JLabel lblMaximumTripValue;
private static JLabel lblMinimumTripValue; private static JLabel lblMinimumTripValue;
private static JLabel lblBusesArrivedInTheLastHourValue; private static JLabel lblBusesArrivedInTheLastHourValue;
private static JLabel lblAverageTripForLastHourValue; private static JLabel lblAverageTripForLastHourValue;
private static JButton btnPause; private static JButton btnPause;
private static JLabel lblAverageTimeForTheTrip; private static JLabel lblAverageTimeForTheTrip;
private static JLabel lblArrivedToArafatTime; private static JLabel lblArrivedToArafatTime;
private static JLabel lblArrivedToHotelsTime; private static JLabel lblArrivedToHotelsTime;
@ -56,7 +56,6 @@ public class MakkahCity {
public static void main(String[] args) { public static void main(String[] args) {
//TODO: fix state errors
t.start(); t.start();
//Gen Camp //Gen Camp
campPerDistrict[District.ALMANSOOR.ordinal()] = new ArrayList<>(); campPerDistrict[District.ALMANSOOR.ordinal()] = new ArrayList<>();
@ -439,16 +438,16 @@ public class MakkahCity {
clearDoneCivilVehicles(); clearDoneCivilVehicles();
addCivilVehicleNoise(); addCivilVehicleNoise();
for (Vehicle vehicle : listOfVehicles) { for (Vehicle vehicle : listOfVehicles) {
if (vehicle.getRoute() == null) if (vehicle.getRoute() == null || vehicle.isArrivedToDest())
continue; continue;
Route route = vehicle.getRoute(); Route route = vehicle.getRoute();
double currentLocation = vehicle.getCurrentLocation(); double currentLocation = vehicle.getCurrentLocation();
if (vehicle.getCurrentStreet() == null && if (vehicle.getCurrentStreet() == null &&
firstDayTimeMan.getCurrentCalendar().get(Calendar.MINUTE) % 2 == 0 && firstDayTimeMan.getCurrentCalendar().get(Calendar.MINUTE) % 2 == 0 &&
route.getStreets()[0].capcityPoint(0,1000) < 1) { route.getStreets()[0].capcityPoint(0,1000) < 1) {
vehicle.setCurrentStreet(route.getStreets()[0]); vehicle.setCurrentStreet(route.getStreets()[0]);
} }
if (vehicle.getCurrentStreet() != null && vehicle.getCurrentStreet().capcityPoint(currentLocation, if (vehicle.getCurrentStreet() != null && vehicle.getCurrentStreet().capcityPoint(currentLocation,
currentLocation+1000) < 1 ) { currentLocation+1000) < 1 ) {
if (currentLocation >= vehicle.getCurrentStreet().getLength()) { if (currentLocation >= vehicle.getCurrentStreet().getLength()) {
@ -457,11 +456,8 @@ public class MakkahCity {
} }
if (!vehicle.isArrivedToDest()) { if (!vehicle.isArrivedToDest()) {
double factor = 1-(vehicle.getCurrentStreet().capcityPoint(vehicle.getCurrentLocation(), double factor = 1-(vehicle.getCurrentStreet().capcityPoint(vehicle.getCurrentLocation(),
vehicle.getCurrentLocation()+1000,vehicle)) ; vehicle.getCurrentLocation()+1000,vehicle)) ;
if (vehicle instanceof Bus) vehicle.move(Bus.MAX_FORWARD * factor ); vehicle.move(vehicle.getMaxSpeed()*factor);
else if (vehicle instanceof Sedan) vehicle.move(Sedan.MAX_FORWARD * factor );
else if (vehicle instanceof SUV) vehicle.move(SUV.MAX_FORWARD * factor );
else if (vehicle instanceof Truck) vehicle.move(Bus.MAX_FORWARD * factor );
} }
} }
} }
@ -503,7 +499,7 @@ public class MakkahCity {
clearDoneCivilVehicles(); clearDoneCivilVehicles();
addCivilVehicleNoise(); addCivilVehicleNoise();
for (Vehicle vehicle : listOfVehicles) { for (Vehicle vehicle : listOfVehicles) {
if (vehicle.getRoute() == null) if (vehicle.getRoute() == null || vehicle.isArrivedToDest())
continue; continue;
Route route = vehicle.getRoute(); Route route = vehicle.getRoute();
double currentLocation = vehicle.getCurrentLocation(); double currentLocation = vehicle.getCurrentLocation();
@ -521,10 +517,7 @@ public class MakkahCity {
if (!vehicle.isArrivedToDest()) { if (!vehicle.isArrivedToDest()) {
double factor = 1-(vehicle.getCurrentStreet().capcityPoint(vehicle.getCurrentLocation(), double factor = 1-(vehicle.getCurrentStreet().capcityPoint(vehicle.getCurrentLocation(),
vehicle.getCurrentLocation()+1000,vehicle)) ; vehicle.getCurrentLocation()+1000,vehicle)) ;
if (vehicle instanceof Bus) vehicle.move(Bus.MAX_FORWARD * factor ); vehicle.move(vehicle.getMaxSpeed()* factor);
else if (vehicle instanceof Sedan) vehicle.move(Sedan.MAX_FORWARD * factor );
else if (vehicle instanceof SUV) vehicle.move(SUV.MAX_FORWARD * factor );
else if (vehicle instanceof Truck) vehicle.move(Bus.MAX_FORWARD * factor );
} }
} }
} }
@ -565,15 +558,15 @@ public class MakkahCity {
private static void startMenu() { private static void startMenu() {
Scanner in = new Scanner(System.in); Scanner in = new Scanner(System.in);
System.out.println("\n"+currenttimeManager.getCurrentTime()+"\n"+ System.out.println("\n"+currenttimeManager.getCurrentTime()+"\n"+
"---------------------------\n" + "---------------------------\n" +
"[1] View Buses\n" + "[1] View Buses\n" +
"[2] View Streets\n" + "[2] View Streets\n" +
"[3] View Campaigns\n" + "[3] View Campaigns\n" +
"[4] View Routes\n" + "[4] View Routes\n" +
"[5] Print report\n" + "[5] Print report\n" +
"[6] Browse History\n" + "[6] Browse History\n" +
"[7] Continue\n" + "[7] Continue\n" +
"[8] Exit"); "[8] Exit");
String choice = in.next(); String choice = in.next();
//Split into methods? //Split into methods?
if (choice.equals("1")){ if (choice.equals("1")){
@ -592,7 +585,7 @@ public class MakkahCity {
stdStreet[i].getPercentRemainingCapacity()); stdStreet[i].getPercentRemainingCapacity());
} }
String input = in.next(); String input = in.next();
int index = Integer.parseInt(input);//TODO: unhandled ex int index = Integer.parseInt(input);
showStreet(stdStreet[index]); showStreet(stdStreet[index]);
} }
if (choice.equals("4")){ if (choice.equals("4")){
@ -695,9 +688,9 @@ public class MakkahCity {
while (!selected){ while (!selected){
System.out.println(new HijriDate(dummyCal.getTimeInMillis())); System.out.println(new HijriDate(dummyCal.getTimeInMillis()));
System.out.print("[1] Forward\n" + System.out.print("[1] Forward\n" +
"[2] Backward\n" + "[2] Backward\n" +
"[3] Select\n" + "[3] Select\n" +
"[4] Return\n"); "[4] Return\n");
String choice = in.next(); String choice = in.next();
if (choice.equals("1")) dummyCal.roll(Calendar.HOUR, 1); if (choice.equals("1")) dummyCal.roll(Calendar.HOUR, 1);
if (choice.equals("2")) dummyCal.roll(Calendar.HOUR, -1); if (choice.equals("2")) dummyCal.roll(Calendar.HOUR, -1);
@ -784,9 +777,9 @@ public class MakkahCity {
District.ALHIJRA, Mashier.ARAFAT); District.ALHIJRA, Mashier.ARAFAT);
stdRoutes[RouteName.AlHijraToArafat2.ordinal()] = new Route(new Street[]{ stdRoutes[RouteName.AlHijraToArafat2.ordinal()] = new Route(new Street[]{
stdStreet[StreetNames.JABAL_THAWR_STREET.ordinal()], stdStreet[StreetNames.JABAL_THAWR_STREET.ordinal()],
stdStreet[StreetNames.FOURTH_HIGHWAY2.ordinal()], stdStreet[StreetNames.FOURTH_HIGHWAY2.ordinal()],
stdStreet[StreetNames.STREET1.ordinal()] stdStreet[StreetNames.STREET1.ordinal()]
},District.ALHIJRA, Mashier.ARAFAT); },District.ALHIJRA, Mashier.ARAFAT);
stdRoutes[RouteName.AlMansoorToArafat1.ordinal()] = new Route( stdRoutes[RouteName.AlMansoorToArafat1.ordinal()] = new Route(
@ -820,7 +813,7 @@ public class MakkahCity {
stdStreet[StreetNames.KA_STREET.ordinal()], stdStreet[StreetNames.KA_STREET.ordinal()],
stdStreet[StreetNames.STREET2.ordinal()], stdStreet[StreetNames.STREET2.ordinal()],
stdStreet[StreetNames.STREET1.ordinal()] stdStreet[StreetNames.STREET1.ordinal()]
},District.ALAZIZIYA, Mashier.ARAFAT); },District.ALAZIZIYA, Mashier.ARAFAT);
//******Arafat day end //******Arafat day end
@ -911,7 +904,7 @@ public class MakkahCity {
if (street.getName() == StreetNames.IBRAHIM_ALKHALIL2) numOfSedan = (int) (numOfSedan * 1.2); if (street.getName() == StreetNames.IBRAHIM_ALKHALIL2) numOfSedan = (int) (numOfSedan * 1.2);
for (int x = 0; x < numOfSedan; x++) { for (int x = 0; x < numOfSedan; x++) {
Sedan car = new Sedan(getRandom(4, 5)); Sedan car = new Sedan(getRandom(4, 5));
double pointOfEntry = getRandom(0, street.getLength());//TODO: consider getLength - x double pointOfEntry = getRandom(0, street.getLength());
if (street.capcityPoint(pointOfEntry, pointOfEntry+1500) < 1){ if (street.capcityPoint(pointOfEntry, pointOfEntry+1500) < 1){
listOfVehicles.add(car); listOfVehicles.add(car);
car.setCurrentLocation(pointOfEntry); car.setCurrentLocation(pointOfEntry);
@ -924,7 +917,7 @@ public class MakkahCity {
if (street.getName() == StreetNames.FOURTH_HIGHWAY1) numOfTruck = (int) (numOfTruck * 0.5); if (street.getName() == StreetNames.FOURTH_HIGHWAY1) numOfTruck = (int) (numOfTruck * 0.5);
if (street.getName() == StreetNames.FOURTH_HIGHWAY2) numOfTruck = (int) (numOfTruck * 0.5); if (street.getName() == StreetNames.FOURTH_HIGHWAY2) numOfTruck = (int) (numOfTruck * 0.5);
if (street.getName() == StreetNames.STREET3) numOfTruck = (int) (numOfTruck * 1.5); if (street.getName() == StreetNames.STREET3) numOfTruck = (int) (numOfTruck * 1.5);
if (street.getName() == StreetNames.IBRAHIM_ALKHALIL2) numOfSedan = (int) (numOfSedan * 1.2); if (street.getName() == StreetNames.IBRAHIM_ALKHALIL2) numOfTruck = (int) (numOfTruck * 1.2);
for (int x = 0; x < numOfTruck; x++) { for (int x = 0; x < numOfTruck; x++) {
Truck car = new Truck(getRandom(4, 5)); Truck car = new Truck(getRandom(4, 5));
double pointOfEntry = getRandom(0, street.getLength()); double pointOfEntry = getRandom(0, street.getLength());
@ -939,7 +932,7 @@ public class MakkahCity {
if (street.getName() == StreetNames.FOURTH_HIGHWAY1) numOfSUV = (int) (numOfSUV * 0.5); if (street.getName() == StreetNames.FOURTH_HIGHWAY1) numOfSUV = (int) (numOfSUV * 0.5);
if (street.getName() == StreetNames.FOURTH_HIGHWAY2) numOfSUV = (int) (numOfSUV * 0.5); if (street.getName() == StreetNames.FOURTH_HIGHWAY2) numOfSUV = (int) (numOfSUV * 0.5);
if (street.getName() == StreetNames.STREET3) numOfSUV = (int) (numOfSUV * 1.5); if (street.getName() == StreetNames.STREET3) numOfSUV = (int) (numOfSUV * 1.5);
if (street.getName() == StreetNames.IBRAHIM_ALKHALIL2) numOfSUV = (int) (numOfSedan * 1.2); if (street.getName() == StreetNames.IBRAHIM_ALKHALIL2) numOfSUV = (int) (numOfSUV * 1.2);
for (int x = 0; x < numOfSUV; x++) { for (int x = 0; x < numOfSUV; x++) {
SUV car = new SUV(getRandom(4, 5)); SUV car = new SUV(getRandom(4, 5));
double pointOfEntry = getRandom(0, street.getLength()); double pointOfEntry = getRandom(0, street.getLength());
@ -950,7 +943,6 @@ public class MakkahCity {
car.setCurrentStreet(street); car.setCurrentStreet(street);
} }
} }
} }
} }
@ -958,12 +950,6 @@ public class MakkahCity {
return currenttimeManager; return currenttimeManager;
} }
/**
* Find shortest path without respect to traffic
* @param campaign
* @return
*/
private static Route getBestRoute(Campaign campaign , Mashier mashier) { private static Route getBestRoute(Campaign campaign , Mashier mashier) {
//ArrayList<Route> routes = (ArrayList<Route>) Arrays.asList(getRoutesToDistrict(campaign.getHotelDistrict())); //ArrayList<Route> routes = (ArrayList<Route>) Arrays.asList(getRoutesToDistrict(campaign.getHotelDistrict()));
Route[] routes = getRoutesToDistrict(campaign.getHotelDistrict()); Route[] routes = getRoutesToDistrict(campaign.getHotelDistrict());
@ -999,6 +985,11 @@ public class MakkahCity {
return sortingRoute; return sortingRoute;
} }
/**
* Find shortest path without respect to traffic
* @param campaign
* @return
*/
public static Route getShortestRoute(Campaign campaign, Mashier mashier) { public static Route getShortestRoute(Campaign campaign, Mashier mashier) {
Route[] routes = getRoutesToDistrict(campaign.getHotelDistrict()); Route[] routes = getRoutesToDistrict(campaign.getHotelDistrict());
Route route = null; Route route = null;
@ -1035,8 +1026,8 @@ public class MakkahCity {
if (currenttimeManager == firstDayTimeMan) status = " Status: Heading to Arafat"; if (currenttimeManager == firstDayTimeMan) status = " Status: Heading to Arafat";
else status = " Status: Heading to hotels"; else status = " Status: Heading to hotels";
String headerFormat = "******Streets report*****\n" + String headerFormat = "******Streets report*****\n" +
"Time: %s%s\n" + "Time: %s%s\n" +
" Street name |Street Load| Total | Buses | Local Vehicles | Avg. Time |\n"; " Street name |Street Load| Total | Buses | Local Vehicles | Avg. Time |\n";
StringBuilder report = new StringBuilder(); StringBuilder report = new StringBuilder();
report.append(String.format(headerFormat, currenttimeManager.getCurrentTime(), status)); report.append(String.format(headerFormat, currenttimeManager.getCurrentTime(), status));
@ -1082,7 +1073,7 @@ public class MakkahCity {
if (Vehicle.getMaxArrived() != null && Vehicle.getMinArrived() != null) { if (Vehicle.getMaxArrived() != null && Vehicle.getMinArrived() != null) {
report.append(String.format(" Maximum trip %s,", Vehicle.getMaxArrived().timeToString())); report.append(String.format(" Maximum trip %s,", Vehicle.getMaxArrived().timeToString()));
report.append(String.format(" Minimum trip %s", Vehicle.getMinArrived().timeToString())); report.append(String.format(" Minimum trip %s", Vehicle.getMinArrived().timeToString()));
} }
return report.toString(); return report.toString();
} }
@ -1100,7 +1091,7 @@ public class MakkahCity {
for (Campaign campaign : listOfCampaigns){ for (Campaign campaign : listOfCampaigns){
for (Vehicle bus : campaign.getVehicles()){ for (Vehicle bus : campaign.getVehicles()){
if (bus.isArrivedToDest() && bus.getTimeOfArrival().before(now.getTime()) if (bus.isArrivedToDest() && bus.getTimeOfArrival().before(now.getTime())
&& bus.getTimeOfArrival().after(from.getTime())) { && bus.getTimeOfArrival().after(from.getTime())) {
long minutes = (bus.getTimeOfArrival().getTime() - bus.getTimeStartedMoving().getTime())/60000; long minutes = (bus.getTimeOfArrival().getTime() - bus.getTimeStartedMoving().getTime())/60000;
sum+= minutes; sum+= minutes;
counter++; counter++;
@ -1146,7 +1137,7 @@ public class MakkahCity {
for (Campaign campaign : listOfCampaigns) { for (Campaign campaign : listOfCampaigns) {
for (Vehicle vehicle : campaign.getVehicles()){ for (Vehicle vehicle : campaign.getVehicles()){
if (vehicle instanceof Bus && if (vehicle instanceof Bus &&
vehicle.isArrivedToDest()) num++; vehicle.isArrivedToDest()) num++;
} }
} }
return num; return num;
@ -1160,7 +1151,7 @@ public class MakkahCity {
for (Campaign campaign : listOfCampaigns){ for (Campaign campaign : listOfCampaigns){
for (Vehicle bus : campaign.getVehicles()){ for (Vehicle bus : campaign.getVehicles()){
if (bus.isArrivedToDest() && bus.getTimeOfArrival().before(now.getTime()) if (bus.isArrivedToDest() && bus.getTimeOfArrival().before(now.getTime())
&& bus.getTimeOfArrival().after(from.getTime())) { && bus.getTimeOfArrival().after(from.getTime())) {
num++; num++;
} }
} }
@ -1237,7 +1228,7 @@ public class MakkahCity {
if (!result) System.out.println("Could not save state "+currenttimeManager.getCurrentTime().getTime()); if (!result) System.out.println("Could not save state "+currenttimeManager.getCurrentTime().getTime());
} }
private static void updateStreetFrame() { private static void updateStreetFrame() {
Object[][] streetData = new Object[stdStreet.length][6]; Object[][] streetData = new Object[stdStreet.length][6];
for (int i = 0; i < stdStreet.length; i++) { for (int i = 0; i < stdStreet.length; i++) {
streetData[i][0] = stdStreet[i].getName().name(); streetData[i][0] = stdStreet[i].getName().name();
@ -1271,28 +1262,28 @@ public class MakkahCity {
if (lblArrivedToArafatTime.getText().equalsIgnoreCase("N/A")) if (lblArrivedToArafatTime.getText().equalsIgnoreCase("N/A"))
if (allArrivedToArafatTime != null) { if (allArrivedToArafatTime != null) {
lblArrivedToArafatTime.setText(allArrivedToArafatTime.toString()); lblArrivedToArafatTime.setText(allArrivedToArafatTime.toString());
} }
if (lblArrivedToHotelsTime.getText().equalsIgnoreCase("N/A")) if (lblArrivedToHotelsTime.getText().equalsIgnoreCase("N/A"))
if (allArrivedToHotelsTime != null) { if (allArrivedToHotelsTime != null) {
lblArrivedToHotelsTime.setText(allArrivedToHotelsTime.toString()); lblArrivedToHotelsTime.setText(allArrivedToHotelsTime.toString());
}
String status = "";
if (currenttimeManager == firstDayTimeMan) {
status = "Heading to Arafat";
} }
else{
status = "Heading to Hotels";
}
lblDestination.setText(status);
String status = ""; int numberOfBusses = 0;
if (currenttimeManager == firstDayTimeMan) { for (Campaign campaign : listOfCampaigns) {
status = "Heading to Arafat"; numberOfBusses += campaign.getNumberOfBusses();
} }
else{ String bus = String.format("%d", numberOfBusses);
status = "Heading to Hotels"; lblNumOfBuses.setText(bus);
}
lblDestination.setText(status);
int numberOfBusses = 0;
for (Campaign campaign : listOfCampaigns) {
numberOfBusses += campaign.getNumberOfBusses();
}
String bus = String.format("%d", numberOfBusses);
lblNumOfBuses.setText(bus);
String numOfdoneBuses = String.format("%d",getNumberOfArrivedBusses()); String numOfdoneBuses = String.format("%d",getNumberOfArrivedBusses());
lblNumOfDonebuses.setText(numOfdoneBuses); lblNumOfDonebuses.setText(numOfdoneBuses);
@ -1308,44 +1299,44 @@ public class MakkahCity {
lblAverageTripForLastHourValue.setText(avgTimeOfTrip()); lblAverageTripForLastHourValue.setText(avgTimeOfTrip());
lblAverageTimeForTheTrip.setText(getAvgTripForAllDis()); lblAverageTimeForTheTrip.setText(getAvgTripForAllDis());
} }
public static String getAvgTripForAllDis() { public static String getAvgTripForAllDis() {
int sum = 0; int sum = 0;
int counter = 1; int counter = 1;
for (Campaign campaign : listOfCampaigns) { for (Campaign campaign : listOfCampaigns) {
for (Vehicle vehicle : campaign.getVehicles()) { for (Vehicle vehicle : campaign.getVehicles()) {
if (vehicle.isArrivedToDest()) { if (vehicle.isArrivedToDest()) {
long minutes = (vehicle.getTimeOfArrival().getTime() - vehicle.getTimeStartedMoving().getTime())/60000; long minutes = (vehicle.getTimeOfArrival().getTime() - vehicle.getTimeStartedMoving().getTime())/60000;
sum+= minutes; sum+= minutes;
counter++; counter++;
} }
}
}//Make the following a method since it is the same other method
sum = sum /counter;
int hours = sum / 60;
int minutes = sum % 60;
if (hours == 0 && minutes == 0) return "-:--";
return String.format("%2d:%02d", hours,minutes);
}
private static String getDistTimeForLbl() {
int numberOfBusses = 0;
int numberOfArrivedBuses = getNumberOfArrivedBusses();
for (Campaign campaign : listOfCampaigns) {
numberOfBusses += campaign.getNumberOfBusses();
} }
}//Make the following a method since it is the same other method
sum = sum /counter;
int hours = sum / 60;
int minutes = sum % 60;
if (hours == 0 && minutes == 0) return "-:--";
return String.format("%2d:%02d", hours,minutes);
}
boolean Done = isAllArrived(); private static String getDistTimeForLbl() {
if (Done && allArrivedToArafatTime != null) { int numberOfBusses = 0;
return String.format("%s", allArrivedToArafatTime); int numberOfArrivedBuses = getNumberOfArrivedBusses();
}
if (Done && allArrivedToHotelsTime != null) { for (Campaign campaign : listOfCampaigns) {
return String.format("%s",allArrivedToHotelsTime); numberOfBusses += campaign.getNumberOfBusses();
} }
return "N/A";
} boolean Done = isAllArrived();
if (Done && allArrivedToArafatTime != null) {
return String.format("%s", allArrivedToArafatTime);
}
if (Done && allArrivedToHotelsTime != null) {
return String.format("%s",allArrivedToHotelsTime);
}
return "N/A";
}
} }

View File

@ -1,9 +1,9 @@
public class SUV extends CivilVehicle { public class SUV extends CivilVehicle {
private String UID; private short UID;
private static int numeberOfSUV; private static short numeberOfSUV;
private final int TIME_TO_FIX = 15; //in minutes private final short TIME_TO_FIX = 15; //in minutes
public static final int MAX_FORWARD = 1300; public static final short MAX_FORWARD = 1300;
public SUV(double vehicleSize){ public SUV(double vehicleSize){
super(vehicleSize); super(vehicleSize);
@ -21,12 +21,11 @@ public class SUV extends CivilVehicle {
private void generateUID() { private void generateUID() {
numeberOfSUV++; numeberOfSUV++;
this.UID = String.format("SUV%04d", numeberOfSUV); this.UID = numeberOfSUV;
} }
public String getUID(){ public String getUID(){
return this.UID; return String.format("SUV%04d", UID);
} }

View File

@ -1,10 +1,10 @@
public class Sedan extends CivilVehicle { public class Sedan extends CivilVehicle {
private String UID; private short UID;
private static int numeberOfSedan; private static short numeberOfSedan;
private final int TIME_TO_FIX = 15; //in minutes private final short TIME_TO_FIX = 15; //in minutes
public static final int MAX_FORWARD = 1500; // Meter/Min public static final short MAX_FORWARD = 1500; // Meter/Min
public Sedan(double vehicleSize){ public Sedan(double vehicleSize){
super(vehicleSize); super(vehicleSize);
@ -16,12 +16,11 @@ public class Sedan extends CivilVehicle {
private void generateUID() { private void generateUID() {
numeberOfSedan++; numeberOfSedan++;
this.UID = String.format("Sedan%04d", numeberOfSedan); this.UID = numeberOfSedan;
} }
public String getUID(){ public String getUID(){
return this.UID; return String.format("Sedan%04d", UID);
} }
@Override @Override

View File

@ -1,8 +1,8 @@
public class Truck extends CivilVehicle { public class Truck extends CivilVehicle {
private String UID; private short UID;
private static int numeberOfTruck; private static short numeberOfTruck;
private final int TIME_TO_FIX = 20; //in minutes private final short TIME_TO_FIX = 20; //in minutes
@Override @Override
public int getMaxSpeed() { public int getMaxSpeed() {
@ -19,12 +19,13 @@ public class Truck extends CivilVehicle {
} }
private void generateUID() { private void generateUID() {
numeberOfTruck++; numeberOfTruck++;
this.UID = String.format("Truck%04d", numeberOfTruck); this.UID = numeberOfTruck;
} }
public String getUID(){ public String getUID(){
return this.UID; return String.format("Truck%04d", UID);
} }
}
}