Compare commits

..

2 Commits

Author SHA1 Message Date
e3e7bf5ccd Package script:
tar jar and run.sh
2021-01-11 02:34:41 +03:00
b386665e66 Simple run script for MacOS/Linux 2021-01-11 02:16:07 +03:00
9 changed files with 221 additions and 187 deletions

14
package.sh Executable file
View File

@ -0,0 +1,14 @@
#!/bin/bash
GIT=$(command -v git)
HEAD=$(command -v head)
CUT=$(command -v cut)
JAR_ARTIFACT="out/artifacts/Hajj_simulation_jar/Hajj-simulation.jar"
if [ -z $"GIT" ] || [ -z $"HEAD" ] || [ -z $"CUT" ]; then
echo "Tools missing"
exit 1
else
tar -cvf Hajj-Simulation-$(git log | head -n1 | cut -d' ' -f2).tar.gz $JAR_ARTIFACT run.sh
fi

9
run.sh Executable file
View File

@ -0,0 +1,9 @@
#!/bin/bash
jav=$(command -v java)
if [ -z "$jav" ]; then
>&2 echo "Can't find java installation"
else
java -jar out/artifacts/Hajj_simulation_jar/Hajj-simulation.jar
fi

View File

@ -1,11 +1,11 @@
public class Bus extends CivilVehicle { public class Bus extends CivilVehicle {
private int UID; private String UID;
private Campaign campaign; private Campaign campaign;
private static int numeberOfBuses; private static int numeberOfBuses;
private final short TIME_TO_FIX = 20; //in minutes private final int TIME_TO_FIX = 20; //in minutes
public static final short MAX_FORWARD = 900; //Meter/Min public static final int 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 = numeberOfBuses; this.UID = String.format("BUS%04d", numeberOfBuses);
} }
public String getUID(){ public String getUID(){
return String.format("BUS%04d", UID); return this.UID;
} }
public Campaign getCampaign() { public Campaign getCampaign() {

View File

@ -467,6 +467,7 @@ 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(); vehicleData[i][0] = vehicles.get(i).getUID();// TODO: There is an Exception error here;
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,6 +56,7 @@ 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<>();
@ -438,16 +439,16 @@ public class MakkahCity {
clearDoneCivilVehicles(); clearDoneCivilVehicles();
addCivilVehicleNoise(); addCivilVehicleNoise();
for (Vehicle vehicle : listOfVehicles) { for (Vehicle vehicle : listOfVehicles) {
if (vehicle.getRoute() == null || vehicle.isArrivedToDest()) if (vehicle.getRoute() == null)
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()) {
@ -456,8 +457,11 @@ 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)) ;
vehicle.move(vehicle.getMaxSpeed()*factor); if (vehicle instanceof Bus) vehicle.move(Bus.MAX_FORWARD * 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 );
} }
} }
} }
@ -499,7 +503,7 @@ public class MakkahCity {
clearDoneCivilVehicles(); clearDoneCivilVehicles();
addCivilVehicleNoise(); addCivilVehicleNoise();
for (Vehicle vehicle : listOfVehicles) { for (Vehicle vehicle : listOfVehicles) {
if (vehicle.getRoute() == null || vehicle.isArrivedToDest()) if (vehicle.getRoute() == null)
continue; continue;
Route route = vehicle.getRoute(); Route route = vehicle.getRoute();
double currentLocation = vehicle.getCurrentLocation(); double currentLocation = vehicle.getCurrentLocation();
@ -517,7 +521,10 @@ 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)) ;
vehicle.move(vehicle.getMaxSpeed()* factor); if (vehicle instanceof Bus) vehicle.move(Bus.MAX_FORWARD * 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 );
} }
} }
} }
@ -558,15 +565,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")){
@ -585,7 +592,7 @@ public class MakkahCity {
stdStreet[i].getPercentRemainingCapacity()); stdStreet[i].getPercentRemainingCapacity());
} }
String input = in.next(); String input = in.next();
int index = Integer.parseInt(input); int index = Integer.parseInt(input);//TODO: unhandled ex
showStreet(stdStreet[index]); showStreet(stdStreet[index]);
} }
if (choice.equals("4")){ if (choice.equals("4")){
@ -688,9 +695,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);
@ -777,9 +784,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(
@ -813,7 +820,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
@ -904,7 +911,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()); double pointOfEntry = getRandom(0, street.getLength());//TODO: consider getLength - x
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);
@ -917,7 +924,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) numOfTruck = (int) (numOfTruck * 1.2); if (street.getName() == StreetNames.IBRAHIM_ALKHALIL2) numOfSedan = (int) (numOfSedan * 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());
@ -932,7 +939,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) (numOfSUV * 1.2); if (street.getName() == StreetNames.IBRAHIM_ALKHALIL2) numOfSUV = (int) (numOfSedan * 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());
@ -943,6 +950,7 @@ public class MakkahCity {
car.setCurrentStreet(street); car.setCurrentStreet(street);
} }
} }
} }
} }
@ -950,6 +958,12 @@ 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());
@ -985,11 +999,6 @@ 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;
@ -1026,8 +1035,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));
@ -1073,7 +1082,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();
} }
@ -1091,7 +1100,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++;
@ -1137,7 +1146,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;
@ -1151,7 +1160,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++;
} }
} }
@ -1228,7 +1237,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();
@ -1262,28 +1271,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);
@ -1299,44 +1308,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);
}
private static String getDistTimeForLbl() { boolean Done = isAllArrived();
int numberOfBusses = 0; if (Done && allArrivedToArafatTime != null) {
int numberOfArrivedBuses = getNumberOfArrivedBusses(); return String.format("%s", allArrivedToArafatTime);
}
for (Campaign campaign : listOfCampaigns) { if (Done && allArrivedToHotelsTime != null) {
numberOfBusses += campaign.getNumberOfBusses(); return String.format("%s",allArrivedToHotelsTime);
} }
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 short UID; private String UID;
private static short numeberOfSUV; private static int numeberOfSUV;
private final short TIME_TO_FIX = 15; //in minutes private final int TIME_TO_FIX = 15; //in minutes
public static final short MAX_FORWARD = 1300; public static final int MAX_FORWARD = 1300;
public SUV(double vehicleSize){ public SUV(double vehicleSize){
super(vehicleSize); super(vehicleSize);
@ -21,11 +21,12 @@ public class SUV extends CivilVehicle {
private void generateUID() { private void generateUID() {
numeberOfSUV++; numeberOfSUV++;
this.UID = numeberOfSUV; this.UID = String.format("SUV%04d", numeberOfSUV);
} }
public String getUID(){ public String getUID(){
return String.format("SUV%04d", UID); return this.UID;
} }

View File

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

View File

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