Reindent (No Change)

This commit is contained in:
HeshamTB 2021-01-10 22:00:25 +03:00
parent 69c1a19ed9
commit 612c00a3f1

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,13 +46,13 @@ 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;
public static void main(String[] args) { public static void main(String[] args) {
@ -64,11 +64,11 @@ public class MakkahCity {
generateCamps(District.ALAZIZIYA, (int)getRandom(1200, 1400)); generateCamps(District.ALAZIZIYA, (int)getRandom(1200, 1400));
generateCamps(District.ALMANSOOR, (int)getRandom(1600, 1800)); generateCamps(District.ALMANSOOR, (int)getRandom(1600, 1800));
generateCamps(District.ALHIJRA, (int)getRandom(1400, 1600)); generateCamps(District.ALHIJRA, (int)getRandom(1400, 1600));
Collections.shuffle(listOfCampaigns); Collections.shuffle(listOfCampaigns);
fillBusesToList(); fillBusesToList();
makeStreets(); makeStreets();
addCivilVehicleNoise(); addCivilVehicleNoise();
@ -78,9 +78,9 @@ public class MakkahCity {
//GUI //GUI
autoModeCheckBox = new Checkbox(); autoModeCheckBox = new Checkbox();
makkahFrame = new JFrame("Hajj Simulation"); makkahFrame = new JFrame("Hajj Simulation");
//Street data and district for GUI table //Street data and district for GUI table
//Street data //Street data
Object[][] streetData = new Object[stdStreet.length][6]; Object[][] streetData = new Object[stdStreet.length][6];
String[] streetColNames = {"Street Name", "Street Load %", "Total", "Buses", String[] streetColNames = {"Street Name", "Street Load %", "Total", "Buses",
@ -98,7 +98,7 @@ public class MakkahCity {
Object[][] districtData = new Object[campPerDistrict.length][7]; Object[][] districtData = new Object[campPerDistrict.length][7];
String[] districtColNames = {"District", "Campaigns", "Busses", "Arrival %", String[] districtColNames = {"District", "Campaigns", "Busses", "Arrival %",
"Avg. Time", "Best time to Arafat", "Best time to District"}; "Avg. Time", "Best time to Arafat", "Best time to District"};
for (int i = 0; i < campPerDistrict.length; i++) { for (int i = 0; i < campPerDistrict.length; i++) {
districtData[i][0] = campPerDistrict[i].get(0).getHotelDistrict().name(); districtData[i][0] = campPerDistrict[i].get(0).getHotelDistrict().name();
districtData[i][1] = campPerDistrict[i].size(); districtData[i][1] = campPerDistrict[i].size();
@ -108,9 +108,9 @@ public class MakkahCity {
districtData[i][5] = getShortestRoute(campPerDistrict[i].get(0), Mashier.ARAFAT).getFastestTimeOfTravel(new Bus()); districtData[i][5] = getShortestRoute(campPerDistrict[i].get(0), Mashier.ARAFAT).getFastestTimeOfTravel(new Bus());
districtData[i][6] = getShortestRoute(campPerDistrict[i].get(0), Mashier.MINA).getFastestTimeOfTravel(new Bus()); districtData[i][6] = getShortestRoute(campPerDistrict[i].get(0), Mashier.MINA).getFastestTimeOfTravel(new Bus());
} }
//tables //tables
//Street table //Street table
streetTable = new JTable(streetData,streetColNames); streetTable = new JTable(streetData,streetColNames);
streetTable.setEnabled(false); streetTable.setEnabled(false);
@ -135,7 +135,7 @@ public class MakkahCity {
streetTable.getColumnModel().getColumn(5).setPreferredWidth(0); streetTable.getColumnModel().getColumn(5).setPreferredWidth(0);
JScrollPane streetScroll = new JScrollPane(streetTable); JScrollPane streetScroll = new JScrollPane(streetTable);
streetScroll.setBounds(22,100,809,269); streetScroll.setBounds(22,100,809,269);
//District table //District table
districtTable = new JTable(districtData,districtColNames); districtTable = new JTable(districtData,districtColNames);
districtTable.setEnabled(false); districtTable.setEnabled(false);
@ -162,7 +162,7 @@ public class MakkahCity {
districtTable.getColumnModel().getColumn(6).setPreferredWidth(93); districtTable.getColumnModel().getColumn(6).setPreferredWidth(93);
districtTable.revalidate(); districtTable.revalidate();
districtScroll.setBounds(22,420,809,89); districtScroll.setBounds(22,420,809,89);
//Buttons //Buttons
JButton btnViewRoutes = new JButton("View Routes"); JButton btnViewRoutes = new JButton("View Routes");
btnViewRoutes.setBounds(888, 33, 166, 29); btnViewRoutes.setBounds(888, 33, 166, 29);
@ -184,7 +184,7 @@ public class MakkahCity {
pause_flag = true; pause_flag = true;
btnPause.setText("Unpause"); btnPause.setText("Unpause");
}); });
JButton btnViewReport = new JButton("View Report"); JButton btnViewReport = new JButton("View Report");
btnViewReport.setBounds(888, 153, 166, 29); btnViewReport.setBounds(888, 153, 166, 29);
btnViewReport.setFont(new Font("Rockwell", Font.PLAIN, 16)); btnViewReport.setFont(new Font("Rockwell", Font.PLAIN, 16));
@ -195,7 +195,7 @@ public class MakkahCity {
pause_flag = true; pause_flag = true;
btnPause.setText("Unpause"); btnPause.setText("Unpause");
}); });
JButton btnViewStreet = new JButton("View Street"); JButton btnViewStreet = new JButton("View Street");
btnViewStreet.setBounds(888, 113, 166, 29); btnViewStreet.setBounds(888, 113, 166, 29);
btnViewStreet.setFont(new Font("Rockwell", Font.PLAIN, 16)); btnViewStreet.setFont(new Font("Rockwell", Font.PLAIN, 16));
@ -232,7 +232,7 @@ public class MakkahCity {
btnPause.setText("Pause"); btnPause.setText("Pause");
} }
}); });
JButton btnBrowseHistory = new JButton("Browse History"); JButton btnBrowseHistory = new JButton("Browse History");
btnBrowseHistory.setBounds(888, 193, 166, 29); btnBrowseHistory.setBounds(888, 193, 166, 29);
btnBrowseHistory.setBackground(new Color(9,9,9)); btnBrowseHistory.setBackground(new Color(9,9,9));
@ -243,28 +243,28 @@ public class MakkahCity {
pause_flag = true; pause_flag = true;
btnPause.setText("Unpause"); btnPause.setText("Unpause");
}); });
//Label //Label
JLabel lblStreets = new JLabel("Streets"); JLabel lblStreets = new JLabel("Streets");
lblStreets.setFont(new Font("Rockwell", Font.PLAIN, 24)); lblStreets.setFont(new Font("Rockwell", Font.PLAIN, 24));
lblStreets.setForeground(new Color(255, 255, 255)); lblStreets.setForeground(new Color(255, 255, 255));
lblStreets.setBounds(22, 59, 208, 30); lblStreets.setBounds(22, 59, 208, 30);
JLabel lblDistrict = new JLabel("District"); JLabel lblDistrict = new JLabel("District");
lblDistrict.setFont(new Font("Rockwell", Font.PLAIN, 24)); lblDistrict.setFont(new Font("Rockwell", Font.PLAIN, 24));
lblDistrict.setForeground(new Color(255, 255, 255)); lblDistrict.setForeground(new Color(255, 255, 255));
lblDistrict.setBounds(22, 380, 166, 29); lblDistrict.setBounds(22, 380, 166, 29);
JLabel lblTime = new JLabel("Time:"); JLabel lblTime = new JLabel("Time:");
lblTime.setFont(new Font("Rockwell", Font.PLAIN, 16)); lblTime.setFont(new Font("Rockwell", Font.PLAIN, 16));
lblTime.setForeground(new Color(255, 255, 255)); lblTime.setForeground(new Color(255, 255, 255));
lblTime.setBounds(22, 11, 72, 14); lblTime.setBounds(22, 11, 72, 14);
JLabel lblStatus = new JLabel("Status:"); JLabel lblStatus = new JLabel("Status:");
lblStatus.setForeground(new Color(255, 255, 255)); lblStatus.setForeground(new Color(255, 255, 255));
lblStatus.setFont(new Font("Rockwell", Font.PLAIN, 16)); lblStatus.setFont(new Font("Rockwell", Font.PLAIN, 16));
lblStatus.setBounds(343, 9, 72, 18); lblStatus.setBounds(343, 9, 72, 18);
lblDestination = new JLabel(); lblDestination = new JLabel();
lblDestination.setForeground(new Color(255, 255, 255)); lblDestination.setForeground(new Color(255, 255, 255));
lblDestination.setFont(new Font("Rockwell", Font.PLAIN, 16)); lblDestination.setFont(new Font("Rockwell", Font.PLAIN, 16));
@ -274,107 +274,107 @@ public class MakkahCity {
lblDate.setFont(new Font("Rockwell", Font.PLAIN, 16)); lblDate.setFont(new Font("Rockwell", Font.PLAIN, 16));
lblDate.setForeground(Color.WHITE); lblDate.setForeground(Color.WHITE);
lblDate.setBounds(69, 8, 326, 21); lblDate.setBounds(69, 8, 326, 21);
JLabel lblBuses = new JLabel("Buses: "); JLabel lblBuses = new JLabel("Buses: ");
lblBuses.setFont(new Font("Rockwell", Font.PLAIN, 16)); lblBuses.setFont(new Font("Rockwell", Font.PLAIN, 16));
lblBuses.setForeground(new Color(255, 255, 255)); lblBuses.setForeground(new Color(255, 255, 255));
lblBuses.setBackground(new Color(192, 192, 192)); lblBuses.setBackground(new Color(192, 192, 192));
lblBuses.setBounds(22, 532, 56, 14); lblBuses.setBounds(22, 532, 56, 14);
lblNumOfBuses = new JLabel(); lblNumOfBuses = new JLabel();
lblNumOfBuses.setText("0"); lblNumOfBuses.setText("0");
lblNumOfBuses.setBackground(new Color(0, 0, 0)); lblNumOfBuses.setBackground(new Color(0, 0, 0));
lblNumOfBuses.setForeground(new Color(255, 255, 255)); lblNumOfBuses.setForeground(new Color(255, 255, 255));
lblNumOfBuses.setFont(new Font("Rockwell", Font.PLAIN, 16)); lblNumOfBuses.setFont(new Font("Rockwell", Font.PLAIN, 16));
lblNumOfBuses.setBounds(69, 533, 90, 12); lblNumOfBuses.setBounds(69, 533, 90, 12);
JLabel lblBusesDone = new JLabel("Buses Done:"); JLabel lblBusesDone = new JLabel("Buses Done:");
lblBusesDone.setForeground(new Color(255, 255, 255)); lblBusesDone.setForeground(new Color(255, 255, 255));
lblBusesDone.setFont(new Font("Rockwell", Font.PLAIN, 16)); lblBusesDone.setFont(new Font("Rockwell", Font.PLAIN, 16));
lblBusesDone.setBounds(143, 533, 101, 12); lblBusesDone.setBounds(143, 533, 101, 12);
lblNumOfDonebuses = new JLabel(); lblNumOfDonebuses = new JLabel();
lblNumOfDonebuses.setText("0"); lblNumOfDonebuses.setText("0");
lblNumOfDonebuses.setForeground(new Color(255, 255, 255)); lblNumOfDonebuses.setForeground(new Color(255, 255, 255));
lblNumOfDonebuses.setFont(new Font("Rockwell", Font.PLAIN, 16)); lblNumOfDonebuses.setFont(new Font("Rockwell", Font.PLAIN, 16));
lblNumOfDonebuses.setBounds(234, 531, 80, 16); lblNumOfDonebuses.setBounds(234, 531, 80, 16);
JLabel lblMaximumTrip = new JLabel("Maximum Trip:"); JLabel lblMaximumTrip = new JLabel("Maximum Trip:");
lblMaximumTrip.setFont(new Font("Rockwell", Font.PLAIN, 16)); lblMaximumTrip.setFont(new Font("Rockwell", Font.PLAIN, 16));
lblMaximumTrip.setForeground(new Color(255, 255, 255)); lblMaximumTrip.setForeground(new Color(255, 255, 255));
lblMaximumTrip.setBounds(22, 557, 112, 22); lblMaximumTrip.setBounds(22, 557, 112, 22);
lblMaximumTripValue = new JLabel(); lblMaximumTripValue = new JLabel();
lblMaximumTripValue.setText("-:--"); lblMaximumTripValue.setText("-:--");
lblMaximumTripValue.setForeground(new Color(255, 255, 255)); lblMaximumTripValue.setForeground(new Color(255, 255, 255));
lblMaximumTripValue.setFont(new Font("Rockwell", Font.PLAIN, 16)); lblMaximumTripValue.setFont(new Font("Rockwell", Font.PLAIN, 16));
lblMaximumTripValue.setBounds(142, 559, 46, 18); lblMaximumTripValue.setBounds(142, 559, 46, 18);
JLabel lblMinimumTrip = new JLabel("Minimum Trip:"); JLabel lblMinimumTrip = new JLabel("Minimum Trip:");
lblMinimumTrip.setFont(new Font("Rockwell", Font.PLAIN, 16)); lblMinimumTrip.setFont(new Font("Rockwell", Font.PLAIN, 16));
lblMinimumTrip.setForeground(Color.WHITE); lblMinimumTrip.setForeground(Color.WHITE);
lblMinimumTrip.setBounds(22, 587, 112, 18); lblMinimumTrip.setBounds(22, 587, 112, 18);
lblMinimumTripValue = new JLabel("-:--"); lblMinimumTripValue = new JLabel("-:--");
lblMinimumTripValue.setForeground(Color.WHITE); lblMinimumTripValue.setForeground(Color.WHITE);
lblMinimumTripValue.setFont(new Font("Rockwell", Font.PLAIN, 16)); lblMinimumTripValue.setFont(new Font("Rockwell", Font.PLAIN, 16));
lblMinimumTripValue.setBounds(143, 589, 90, 14); lblMinimumTripValue.setBounds(143, 589, 90, 14);
JLabel lblBusesArrivedInTheLastHour = new JLabel("Buses Arrived In The Last Hour:"); JLabel lblBusesArrivedInTheLastHour = new JLabel("Buses Arrived In The Last Hour:");
lblBusesArrivedInTheLastHour.setForeground(Color.WHITE); lblBusesArrivedInTheLastHour.setForeground(Color.WHITE);
lblBusesArrivedInTheLastHour.setFont(new Font("Rockwell", Font.PLAIN, 16)); lblBusesArrivedInTheLastHour.setFont(new Font("Rockwell", Font.PLAIN, 16));
lblBusesArrivedInTheLastHour.setBounds(333, 532, 237, 14); lblBusesArrivedInTheLastHour.setBounds(333, 532, 237, 14);
lblBusesArrivedInTheLastHourValue = new JLabel(); lblBusesArrivedInTheLastHourValue = new JLabel();
lblBusesArrivedInTheLastHourValue.setText("0"); lblBusesArrivedInTheLastHourValue.setText("0");
lblBusesArrivedInTheLastHourValue.setForeground(Color.WHITE); lblBusesArrivedInTheLastHourValue.setForeground(Color.WHITE);
lblBusesArrivedInTheLastHourValue.setFont(new Font("Rockwell", Font.PLAIN, 16)); lblBusesArrivedInTheLastHourValue.setFont(new Font("Rockwell", Font.PLAIN, 16));
lblBusesArrivedInTheLastHourValue.setBounds(566, 532, 90, 14); lblBusesArrivedInTheLastHourValue.setBounds(566, 532, 90, 14);
JLabel lblAverageTripForLastHour = new JLabel("Average Trip For Last Hour:"); JLabel lblAverageTripForLastHour = new JLabel("Average Trip For Last Hour:");
lblAverageTripForLastHour.setForeground(Color.WHITE); lblAverageTripForLastHour.setForeground(Color.WHITE);
lblAverageTripForLastHour.setFont(new Font("Rockwell", Font.PLAIN, 16)); lblAverageTripForLastHour.setFont(new Font("Rockwell", Font.PLAIN, 16));
lblAverageTripForLastHour.setBackground(Color.BLACK); lblAverageTripForLastHour.setBackground(Color.BLACK);
lblAverageTripForLastHour.setBounds(198, 559, 208, 18); lblAverageTripForLastHour.setBounds(198, 559, 208, 18);
lblAverageTripForLastHourValue = new JLabel("(No Arrivals) In Last Hour"); lblAverageTripForLastHourValue = new JLabel("(No Arrivals) In Last Hour");
lblAverageTripForLastHourValue.setForeground(Color.WHITE); lblAverageTripForLastHourValue.setForeground(Color.WHITE);
lblAverageTripForLastHourValue.setFont(new Font("Rockwell", Font.PLAIN, 16)); lblAverageTripForLastHourValue.setFont(new Font("Rockwell", Font.PLAIN, 16));
lblAverageTripForLastHourValue.setBounds(408, 557, 216, 18); lblAverageTripForLastHourValue.setBounds(408, 557, 216, 18);
JLabel lblAvgTime = new JLabel("Average Time For The Trip:"); JLabel lblAvgTime = new JLabel("Average Time For The Trip:");
lblAvgTime.setForeground(Color.WHITE); lblAvgTime.setForeground(Color.WHITE);
lblAvgTime.setFont(new Font("Rockwell", Font.PLAIN, 16)); lblAvgTime.setFont(new Font("Rockwell", Font.PLAIN, 16));
lblAvgTime.setBounds(198, 582, 208, 29); lblAvgTime.setBounds(198, 582, 208, 29);
lblAverageTimeForTheTrip = new JLabel("-:--"); lblAverageTimeForTheTrip = new JLabel("-:--");
lblAverageTimeForTheTrip.setForeground(Color.WHITE); lblAverageTimeForTheTrip.setForeground(Color.WHITE);
lblAverageTimeForTheTrip.setFont(new Font("Rockwell", Font.PLAIN, 16)); lblAverageTimeForTheTrip.setFont(new Font("Rockwell", Font.PLAIN, 16));
lblAverageTimeForTheTrip.setBounds(408, 589, 101, 14); lblAverageTimeForTheTrip.setBounds(408, 589, 101, 14);
JLabel lblArrivedToArafat = new JLabel("All Arrived To Arafat At:"); JLabel lblArrivedToArafat = new JLabel("All Arrived To Arafat At:");
lblArrivedToArafat.setFont(new Font("Rockwell", Font.PLAIN, 16)); lblArrivedToArafat.setFont(new Font("Rockwell", Font.PLAIN, 16));
lblArrivedToArafat.setForeground(Color.WHITE); lblArrivedToArafat.setForeground(Color.WHITE);
lblArrivedToArafat.setBounds(18, 613, 216, 14); lblArrivedToArafat.setBounds(18, 613, 216, 14);
makkahFrame.getContentPane().add(lblArrivedToArafat); makkahFrame.getContentPane().add(lblArrivedToArafat);
JLabel lblArrivedToHotels = new JLabel("All Arrived To Hotels At:"); JLabel lblArrivedToHotels = new JLabel("All Arrived To Hotels At:");
lblArrivedToHotels.setFont(new Font("Rockwell", Font.PLAIN, 16)); lblArrivedToHotels.setFont(new Font("Rockwell", Font.PLAIN, 16));
lblArrivedToHotels.setForeground(Color.WHITE); lblArrivedToHotels.setForeground(Color.WHITE);
lblArrivedToHotels.setBounds(18, 638, 184, 14); lblArrivedToHotels.setBounds(18, 638, 184, 14);
makkahFrame.getContentPane().add(lblArrivedToHotels); makkahFrame.getContentPane().add(lblArrivedToHotels);
lblArrivedToArafatTime = new JLabel("N/A"); lblArrivedToArafatTime = new JLabel("N/A");
lblArrivedToArafatTime.setFont(new Font("Rockwell", Font.PLAIN, 16)); lblArrivedToArafatTime.setFont(new Font("Rockwell", Font.PLAIN, 16));
lblArrivedToArafatTime.setForeground(Color.WHITE); lblArrivedToArafatTime.setForeground(Color.WHITE);
lblArrivedToArafatTime.setBounds(208, 613, 358, 14); lblArrivedToArafatTime.setBounds(208, 613, 358, 14);
makkahFrame.getContentPane().add(lblArrivedToArafatTime); makkahFrame.getContentPane().add(lblArrivedToArafatTime);
lblArrivedToHotelsTime = new JLabel("N/A"); lblArrivedToHotelsTime = new JLabel("N/A");
lblArrivedToHotelsTime.setFont(new Font("Rockwell", Font.PLAIN, 16)); lblArrivedToHotelsTime.setFont(new Font("Rockwell", Font.PLAIN, 16));
lblArrivedToHotelsTime.setForeground(Color.WHITE); lblArrivedToHotelsTime.setForeground(Color.WHITE);
lblArrivedToHotelsTime.setBounds(208, 638, 358, 14); lblArrivedToHotelsTime.setBounds(208, 638, 358, 14);
//Add Elements //Add Elements
makkahFrame.getContentPane().add(streetScroll); makkahFrame.getContentPane().add(streetScroll);
makkahFrame.getContentPane().add(lblAverageTimeForTheTrip); makkahFrame.getContentPane().add(lblAverageTimeForTheTrip);
@ -405,7 +405,7 @@ public class MakkahCity {
makkahFrame.getContentPane().add(lblMinimumTrip); makkahFrame.getContentPane().add(lblMinimumTrip);
makkahFrame.getContentPane().add(btnBrowseHistory); makkahFrame.getContentPane().add(btnBrowseHistory);
makkahFrame.getContentPane().add(btnPause); makkahFrame.getContentPane().add(btnPause);
//Frame Settings //Frame Settings
makkahFrame.getContentPane().setBackground(new Color(50,50,50)); makkahFrame.getContentPane().setBackground(new Color(50,50,50));
makkahFrame.getContentPane().setForeground(new Color(0, 0, 0)); makkahFrame.getContentPane().setForeground(new Color(0, 0, 0));
@ -418,11 +418,11 @@ public class MakkahCity {
makkahFrame.setLocation(200,150); makkahFrame.setLocation(200,150);
makkahFrame.setAutoRequestFocus(false); makkahFrame.setAutoRequestFocus(false);
makkahFrame.setVisible(true); makkahFrame.setVisible(true);
//Set Routes for Campaigns //Set Routes for Campaigns
while(!firstDayTimeMan.isEnded()) { while(!firstDayTimeMan.isEnded()) {
checkInput(); checkInput();
if (!isAllRoutSet) { if (!isAllRoutSet) {
isAllRoutSet = true; isAllRoutSet = true;
setRoutesForCampaigns(Mashier.ARAFAT); setRoutesForCampaigns(Mashier.ARAFAT);
@ -443,11 +443,11 @@ public class MakkahCity {
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,7 +456,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 ); 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 Sedan) vehicle.move(Sedan.MAX_FORWARD * factor );
else if (vehicle instanceof SUV) vehicle.move(SUV.MAX_FORWARD * factor ); else if (vehicle instanceof SUV) vehicle.move(SUV.MAX_FORWARD * factor );
@ -469,7 +469,7 @@ public class MakkahCity {
lblDate.setText(currenttimeManager.getCurrentTime().toString()); lblDate.setText(currenttimeManager.getCurrentTime().toString());
//lblArrivedToArafatTime.setText(getDistTimeForLbl()); //lblArrivedToArafatTime.setText(getDistTimeForLbl());
} }
currenttimeManager = lastDayTimeMan; currenttimeManager = lastDayTimeMan;
System.out.println("\n***************FINSHIED ARAFAT DAY***************"); System.out.println("\n***************FINSHIED ARAFAT DAY***************");
//Collections.shuffle(listOfVehicles); //Collections.shuffle(listOfVehicles);
@ -564,15 +564,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")){
@ -694,9 +694,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);
@ -783,9 +783,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(
@ -819,7 +819,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
@ -893,9 +893,9 @@ public class MakkahCity {
private static void addCivilVehicleNoise() { private static void addCivilVehicleNoise() {
for (Street street: stdStreet) { for (Street street: stdStreet) {
if (street.getPercentRemainingCapacity() >= 80) if (street.getPercentRemainingCapacity() >= 80)
continue; continue;
int numOfSedan = (int)getRandom(10,15); int numOfSedan = (int)getRandom(10,15);
int numOfSUV = (int)getRandom(5,9); int numOfSUV = (int)getRandom(5,9);
int numOfTruck = (int)getRandom(3,6); int numOfTruck = (int)getRandom(3,6);
@ -955,7 +955,7 @@ public class MakkahCity {
public static PDate getTimeMan() { public static PDate getTimeMan() {
return currenttimeManager; return currenttimeManager;
} }
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());
@ -974,14 +974,14 @@ public class MakkahCity {
} }
return null; return null;
} }
private static Route[] sortRoutes(Route[] routes) { private static Route[] sortRoutes(Route[] routes) {
Route[] sortingRoute = new Route[routes.length]; Route[] sortingRoute = new Route[routes.length];
double[] lengthes = new double[routes.length]; double[] lengthes = new double[routes.length];
for (int i = 0; i < lengthes.length ; i++) for (int i = 0; i < lengthes.length ; i++)
lengthes[i] = routes[i].getTotalLength(); lengthes[i] = routes[i].getTotalLength();
Arrays.sort(lengthes); Arrays.sort(lengthes);
for (int i = 0; i < lengthes.length ; i++) { for (int i = 0; i < lengthes.length ; i++) {
for (Route r : routes) for (Route r : routes)
@ -1026,14 +1026,14 @@ public class MakkahCity {
Route[] routesArray = new Route[routes.size()]; Route[] routesArray = new Route[routes.size()];
return routes.toArray(routesArray); return routes.toArray(routesArray);
} }
private static String getStreetsReport() { private static String getStreetsReport() {
String status = ""; String status = "";
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));
@ -1054,7 +1054,7 @@ public class MakkahCity {
report.append(preSimulationReport()).append("Type m+Enter to view menu"); report.append(preSimulationReport()).append("Type m+Enter to view menu");
return report.toString(); return report.toString();
} }
private static String getFinalRep() { private static String getFinalRep() {
StringBuilder s = new StringBuilder(); StringBuilder s = new StringBuilder();
int numberOfBusses = 0; int numberOfBusses = 0;
@ -1062,7 +1062,7 @@ public class MakkahCity {
//Redundant loops slow down execution. find better sol. //Redundant loops slow down execution. find better sol.
for (Campaign campaign : listOfCampaigns) { for (Campaign campaign : listOfCampaigns) {
numberOfBusses += campaign.getNumberOfBusses(); numberOfBusses += campaign.getNumberOfBusses();
} }
String fFormat = "All arrived to %s at: %s"; String fFormat = "All arrived to %s at: %s";
boolean arr = isAllArrived();//since it has looping. use once. boolean arr = isAllArrived();//since it has looping. use once.
if (arr && allArrivedToArafatTime != null) if (arr && allArrivedToArafatTime != null)
@ -1073,13 +1073,13 @@ public class MakkahCity {
numberOfBusses, numberOfArrivedBuses, minMaxRep() , getNumberOfArrivedBussesPerHour(), avgTimeOfTrip())); numberOfBusses, numberOfArrivedBuses, minMaxRep() , getNumberOfArrivedBussesPerHour(), avgTimeOfTrip()));
return s.toString(); return s.toString();
} }
private static String minMaxRep() { private static String minMaxRep() {
StringBuilder report = new StringBuilder(); StringBuilder report = new StringBuilder();
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();
} }
@ -1097,7 +1097,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++;
@ -1143,7 +1143,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;
@ -1157,19 +1157,19 @@ 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++;
} }
} }
} }
return num; return num;
} }
private static boolean isAllArrived() { private static boolean isAllArrived() {
for (Campaign campaign : listOfCampaigns) for (Campaign campaign : listOfCampaigns)
if (!campaign.isDone()) if (!campaign.isDone())
return false; return false;
return true; return true;
} }
@ -1234,7 +1234,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();
@ -1268,82 +1268,82 @@ 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);
if (Vehicle.getMaxArrived() != null && Vehicle.getMinArrived() != null) { if (Vehicle.getMaxArrived() != null && Vehicle.getMinArrived() != null) {
lblMaximumTripValue.setText(Vehicle.getMaxArrived().getTripTime().toString()); lblMaximumTripValue.setText(Vehicle.getMaxArrived().getTripTime().toString());
lblMinimumTripValue.setText(Vehicle.getMinArrived().getTripTime().toString()); lblMinimumTripValue.setText(Vehicle.getMinArrived().getTripTime().toString());
} }
String NumberOfBussPerHour = String.format("%d", getNumberOfArrivedBussesPerHour()); String NumberOfBussPerHour = String.format("%d", getNumberOfArrivedBussesPerHour());
lblBusesArrivedInTheLastHourValue.setText(NumberOfBussPerHour); lblBusesArrivedInTheLastHourValue.setText(NumberOfBussPerHour);
lblAverageTripForLastHourValue.setText(avgTimeOfTrip()); lblAverageTripForLastHourValue.setText(avgTimeOfTrip());
lblAverageTimeForTheTrip.setText(getAvgTripForAllDis()); lblAverageTimeForTheTrip.setText(getAvgTripForAllDis());
}
public static String getAvgTripForAllDis() {
int sum = 0;
int counter = 1;
for (Campaign campaign : listOfCampaigns) {
for (Vehicle vehicle : campaign.getVehicles()) {
if (vehicle.isArrivedToDest()) {
long minutes = (vehicle.getTimeOfArrival().getTime() - vehicle.getTimeStartedMoving().getTime())/60000;
sum+= minutes;
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(); public static String getAvgTripForAllDis() {
int sum = 0;
for (Campaign campaign : listOfCampaigns) { int counter = 1;
numberOfBusses += campaign.getNumberOfBusses(); for (Campaign campaign : listOfCampaigns) {
} for (Vehicle vehicle : campaign.getVehicles()) {
if (vehicle.isArrivedToDest()) {
boolean Done = isAllArrived(); long minutes = (vehicle.getTimeOfArrival().getTime() - vehicle.getTimeStartedMoving().getTime())/60000;
if (Done && allArrivedToArafatTime != null) { sum+= minutes;
return String.format("%s", allArrivedToArafatTime); counter++;
}
} }
if (Done && allArrivedToHotelsTime != null) { }//Make the following a method since it is the same other method
return String.format("%s",allArrivedToHotelsTime); sum = sum /counter;
} int hours = sum / 60;
return "N/A"; 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();
}
boolean Done = isAllArrived();
if (Done && allArrivedToArafatTime != null) {
return String.format("%s", allArrivedToArafatTime);
}
if (Done && allArrivedToHotelsTime != null) {
return String.format("%s",allArrivedToHotelsTime);
}
return "N/A";
}
} }