Compare commits
	
		
			3 Commits
		
	
	
		
			master
			...
			add-loggin
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| aa5cc9b68b | |||
| 1fa3e4f5f1 | |||
| 2d8456c975 | 
@ -1,6 +0,0 @@
 | 
			
		||||
<?xml version="1.0" encoding="UTF-8"?>
 | 
			
		||||
<classpath>
 | 
			
		||||
	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
 | 
			
		||||
	<classpathentry kind="src" path="src"/>
 | 
			
		||||
	<classpathentry kind="output" path="bin"/>
 | 
			
		||||
</classpath>
 | 
			
		||||
							
								
								
									
										3
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										3
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							@ -1,5 +1,2 @@
 | 
			
		||||
out/
 | 
			
		||||
/bin/
 | 
			
		||||
*.jpeg
 | 
			
		||||
*.zip
 | 
			
		||||
*.bin
 | 
			
		||||
 | 
			
		||||
@ -2,6 +2,9 @@
 | 
			
		||||
  <artifact type="jar" build-on-make="true" name="Hajj-simulation:jar">
 | 
			
		||||
    <output-path>$PROJECT_DIR$/out/artifacts/Hajj_simulation_jar</output-path>
 | 
			
		||||
    <root id="archive" name="Hajj-simulation.jar">
 | 
			
		||||
      <element id="directory" name="META-INF">
 | 
			
		||||
        <element id="file-copy" path="$PROJECT_DIR$/out/META-INF/MANIFEST.MF" />
 | 
			
		||||
      </element>
 | 
			
		||||
      <element id="module-output" name="Hajj-simulation" />
 | 
			
		||||
    </root>
 | 
			
		||||
  </artifact>
 | 
			
		||||
 | 
			
		||||
@ -1,6 +1,6 @@
 | 
			
		||||
<?xml version="1.0" encoding="UTF-8"?>
 | 
			
		||||
<project version="4">
 | 
			
		||||
  <component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="11" project-jdk-type="JavaSDK">
 | 
			
		||||
  <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
 | 
			
		||||
    <output url="file://$PROJECT_DIR$/out" />
 | 
			
		||||
  </component>
 | 
			
		||||
</project>
 | 
			
		||||
							
								
								
									
										17
									
								
								.project
									
									
									
									
									
								
							
							
						
						
									
										17
									
								
								.project
									
									
									
									
									
								
							@ -1,17 +0,0 @@
 | 
			
		||||
<?xml version="1.0" encoding="UTF-8"?>
 | 
			
		||||
<projectDescription>
 | 
			
		||||
	<name>Hajj-simulation</name>
 | 
			
		||||
	<comment></comment>
 | 
			
		||||
	<projects>
 | 
			
		||||
	</projects>
 | 
			
		||||
	<buildSpec>
 | 
			
		||||
		<buildCommand>
 | 
			
		||||
			<name>org.eclipse.jdt.core.javabuilder</name>
 | 
			
		||||
			<arguments>
 | 
			
		||||
			</arguments>
 | 
			
		||||
		</buildCommand>
 | 
			
		||||
	</buildSpec>
 | 
			
		||||
	<natures>
 | 
			
		||||
		<nature>org.eclipse.jdt.core.javanature</nature>
 | 
			
		||||
	</natures>
 | 
			
		||||
</projectDescription>
 | 
			
		||||
							
								
								
									
										14
									
								
								package.sh
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								package.sh
									
									
									
									
									
								
							@ -1,14 +0,0 @@
 | 
			
		||||
#!/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
									
									
									
									
									
								
							
							
						
						
									
										9
									
								
								run.sh
									
									
									
									
									
								
							@ -1,9 +0,0 @@
 | 
			
		||||
#!/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
 | 
			
		||||
@ -30,14 +30,6 @@ public class Bus extends CivilVehicle {
 | 
			
		||||
        return TIME_TO_FIX;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    @Override
 | 
			
		||||
    public String toString() {
 | 
			
		||||
        StringBuilder s = new StringBuilder();
 | 
			
		||||
        s.append(String.format("ID: %s, Campaign ID: %s\n",this.getUID() , getCampaign().getUID()));
 | 
			
		||||
        s.append(super.toString());
 | 
			
		||||
        return s.toString();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void generateUID() {
 | 
			
		||||
        numeberOfBuses++;
 | 
			
		||||
        this.UID = String.format("BUS%04d", numeberOfBuses);
 | 
			
		||||
 | 
			
		||||
@ -1,8 +1,7 @@
 | 
			
		||||
import java.io.Serializable;
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.Date;
 | 
			
		||||
 | 
			
		||||
public class Campaign implements Serializable {
 | 
			
		||||
public class Campaign {
 | 
			
		||||
 | 
			
		||||
    private String UID;
 | 
			
		||||
    private int numberOfAriivedBuses;
 | 
			
		||||
@ -124,13 +123,4 @@ public class Campaign implements Serializable {
 | 
			
		||||
    public int getPercentArrived() {
 | 
			
		||||
        return ((numberOfAriivedBuses/vehicles.size()) *100);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public String toString(){
 | 
			
		||||
        return String.format("ID: %s\n" +
 | 
			
		||||
                "District: %s\n" +
 | 
			
		||||
                "Bueses: %d, Arrived buses: %d\n",
 | 
			
		||||
                getUID(),
 | 
			
		||||
                getHotelDistrict().name(),
 | 
			
		||||
                getNumberOfBusses(), getNumberOfArrivedBuses());
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -1,182 +0,0 @@
 | 
			
		||||
import java.io.*;
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.Date;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
public class DataManeger {
 | 
			
		||||
 | 
			
		||||
    private File workingDir;
 | 
			
		||||
 | 
			
		||||
    public DataManeger(){
 | 
			
		||||
        workingDir = new File("./data/");
 | 
			
		||||
        workingDir.mkdir();
 | 
			
		||||
        clearData();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean stateAvailable(Date time) {
 | 
			
		||||
        File f = new File(String.format("./data/%s.bin", time.getTime()));
 | 
			
		||||
        return f.exists();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public State loadState(Date time){
 | 
			
		||||
        State state = null;
 | 
			
		||||
        if (stateAvailable(time)){
 | 
			
		||||
            try {
 | 
			
		||||
                ObjectInputStream objectInputStream = new ObjectInputStream(
 | 
			
		||||
                        new FileInputStream(String.format("./data/%s.bin", time.getTime())));
 | 
			
		||||
                state = (State)objectInputStream.readObject();
 | 
			
		||||
                objectInputStream.close();
 | 
			
		||||
            } catch (IOException | ClassNotFoundException e) {
 | 
			
		||||
                e.printStackTrace();
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        return state;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean saveState(State state, Date time){
 | 
			
		||||
        try {
 | 
			
		||||
            FileOutputStream fs = new FileOutputStream(String.format("./data/%s.bin", time.getTime()));
 | 
			
		||||
            BufferedOutputStream bfs = new BufferedOutputStream(fs);
 | 
			
		||||
            ObjectOutputStream objectOutputStream = new ObjectOutputStream(bfs);
 | 
			
		||||
            objectOutputStream.writeObject(state);
 | 
			
		||||
            objectOutputStream.close();
 | 
			
		||||
        } catch (IOException e) {
 | 
			
		||||
            e.printStackTrace();
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public File[] savedStateFiles() {
 | 
			
		||||
        return workingDir.listFiles();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Date[] savedStatesTimes() {
 | 
			
		||||
        File[] files = savedStateFiles();
 | 
			
		||||
        ArrayList<Date> timesList = new ArrayList<>();
 | 
			
		||||
        for (File file : files){
 | 
			
		||||
            if (file.getName().contains(".bin")){
 | 
			
		||||
                String timeInName = file.getName().replaceAll(".bin", "").trim();
 | 
			
		||||
                if ("".equals(timeInName)) continue;
 | 
			
		||||
                long time = Long.parseLong(timeInName);
 | 
			
		||||
                timesList.add(new HijriDate(time));
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        Date[] times = new Date[timesList.size()];
 | 
			
		||||
        times = timesList.toArray(times);
 | 
			
		||||
        return times;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public List<State> getStates(){
 | 
			
		||||
        List<State> list = new ArrayList<>();
 | 
			
		||||
        for (File file : workingDir.listFiles()) {
 | 
			
		||||
            if (file.getName().contains(".bin")){
 | 
			
		||||
                try {
 | 
			
		||||
                    FileInputStream fileInputStream = new FileInputStream(file);
 | 
			
		||||
                    BufferedInputStream bufferedInputStream = new BufferedInputStream(fileInputStream);
 | 
			
		||||
                    ObjectInputStream objectInputStream = new ObjectInputStream(bufferedInputStream);
 | 
			
		||||
                    State state = (State) objectInputStream.readObject();
 | 
			
		||||
                    list.add(state);
 | 
			
		||||
                } catch (IOException | ClassNotFoundException e) {
 | 
			
		||||
                    e.printStackTrace();
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        return list;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void clearData() {
 | 
			
		||||
        for (File file : savedStateFiles()) {
 | 
			
		||||
            if (file.getName().contains(".bin")){
 | 
			
		||||
                file.delete();
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
class State implements Serializable {
 | 
			
		||||
 | 
			
		||||
    //A better implementation is to make this more general or make Makkah an instance.
 | 
			
		||||
 | 
			
		||||
    private ArrayList<Campaign> listOfCampaigns;
 | 
			
		||||
    private ArrayList<Vehicle> listOfVehicles;
 | 
			
		||||
    private ArrayList<Campaign>[] campPerDistrict;
 | 
			
		||||
    private Route[] stdRoutes;
 | 
			
		||||
    private Street[] stdStreet;
 | 
			
		||||
    private Date allArrivedToArafatTime;
 | 
			
		||||
    private Date allArrivedToHotelsTime;
 | 
			
		||||
    private Date stateTime;
 | 
			
		||||
    private String maxTrip;
 | 
			
		||||
    private String minTrip;
 | 
			
		||||
 | 
			
		||||
    public State(ArrayList<Campaign> listOfCampaigns,
 | 
			
		||||
                 ArrayList<Vehicle> listOfVehicles,
 | 
			
		||||
                 ArrayList<Campaign>[] campPerDistrict,
 | 
			
		||||
                 Route[] stdRoutes,
 | 
			
		||||
                 Street[] stdStreet,
 | 
			
		||||
                 Date allArrivedToArafatTime,
 | 
			
		||||
                 Date allArrivedToHotelsTime,
 | 
			
		||||
                 Date stateTime) {
 | 
			
		||||
        //Make clones since values may change if this is running on a thread.
 | 
			
		||||
        this.listOfCampaigns = (ArrayList<Campaign>) listOfCampaigns.clone();
 | 
			
		||||
        this.listOfVehicles = (ArrayList<Vehicle>) listOfVehicles.clone();
 | 
			
		||||
        this.campPerDistrict = (ArrayList<Campaign>[])campPerDistrict.clone();
 | 
			
		||||
        this.stdRoutes = stdRoutes.clone();
 | 
			
		||||
        this.stdStreet = stdStreet.clone();
 | 
			
		||||
        if (allArrivedToArafatTime != null) {
 | 
			
		||||
            this.allArrivedToArafatTime = (Date) allArrivedToArafatTime.clone();
 | 
			
		||||
        }
 | 
			
		||||
        if (allArrivedToHotelsTime != null) {
 | 
			
		||||
            this.allArrivedToHotelsTime = (Date) allArrivedToHotelsTime.clone();
 | 
			
		||||
        }
 | 
			
		||||
        this.stateTime = stateTime;
 | 
			
		||||
        if (Vehicle.getMinArrived() != null && Vehicle.getMaxArrived() != null){
 | 
			
		||||
            this.maxTrip = Vehicle.getMaxArrived().getTripTime();
 | 
			
		||||
            this.minTrip = Vehicle.getMinArrived().getTripTime();
 | 
			
		||||
        }
 | 
			
		||||
        else {
 | 
			
		||||
            this.maxTrip = "N/A";
 | 
			
		||||
            this.minTrip = "N/A";
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public ArrayList<Campaign> getListOfCampaigns() {
 | 
			
		||||
        return listOfCampaigns;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public ArrayList<Vehicle> getListOfVehicles() {
 | 
			
		||||
        return listOfVehicles;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    public ArrayList<Campaign>[] getCampPerDistrict() {
 | 
			
		||||
		return campPerDistrict;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public Route[] getStdRoutes() {
 | 
			
		||||
        return stdRoutes;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Street[] getStdStreet() {
 | 
			
		||||
        return stdStreet;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Date getAllArrivedToArafatTime() {
 | 
			
		||||
        return allArrivedToArafatTime;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Date getAllArrivedToHotelsTime() {
 | 
			
		||||
        return allArrivedToHotelsTime;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
	public Date getStateTime() {
 | 
			
		||||
		return stateTime;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
    public String getMaxTrip() {
 | 
			
		||||
        return maxTrip;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public String getMinTrip() {
 | 
			
		||||
        return minTrip;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@ -1,56 +0,0 @@
 | 
			
		||||
import java.awt.EventQueue;
 | 
			
		||||
import javax.swing.JFrame;
 | 
			
		||||
import javax.swing.JLabel;
 | 
			
		||||
import java.awt.BorderLayout;
 | 
			
		||||
import javax.swing.JPanel;
 | 
			
		||||
import java.awt.Font;
 | 
			
		||||
import java.awt.Color;
 | 
			
		||||
import javax.swing.JScrollBar;
 | 
			
		||||
import javax.swing.JTextField;
 | 
			
		||||
import java.awt.FlowLayout;
 | 
			
		||||
import java.awt.GridBagLayout;
 | 
			
		||||
import java.awt.GridBagConstraints;
 | 
			
		||||
import java.awt.Insets;
 | 
			
		||||
import javax.swing.JScrollPane;
 | 
			
		||||
 | 
			
		||||
public class EventControll {
 | 
			
		||||
 | 
			
		||||
	private JFrame frame;
 | 
			
		||||
	//private JTextField textField;
 | 
			
		||||
	private JTextField textField_2;
 | 
			
		||||
	private JTextField textField_3;
 | 
			
		||||
	private JTextField textField_4;
 | 
			
		||||
	public static void main(String[] args) {
 | 
			
		||||
		EventQueue.invokeLater(new Runnable() {
 | 
			
		||||
			public void run() {
 | 
			
		||||
				try {
 | 
			
		||||
					EventControll window = new EventControll();
 | 
			
		||||
					window.frame.setVisible(true);
 | 
			
		||||
				} catch (Exception e) {
 | 
			
		||||
					e.printStackTrace();
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		});
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public EventControll() {
 | 
			
		||||
		initialize();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private void initialize() {
 | 
			
		||||
		frame = new JFrame();
 | 
			
		||||
		frame.getContentPane().setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
 | 
			
		||||
		
 | 
			
		||||
		for (int i = 0; i<10 ; i++) {
 | 
			
		||||
			JTextField textField = new JTextField();
 | 
			
		||||
			int x =(int)(((double)i/9.0)*255);
 | 
			
		||||
			textField.setBackground(new Color(255,x,0));
 | 
			
		||||
			frame.getContentPane().add(textField);
 | 
			
		||||
			textField.setColumns(10);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public void setData(Object A) {
 | 
			
		||||
		//lblNewLabel.setText(A.toString());
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
@ -1,512 +0,0 @@
 | 
			
		||||
import java.awt.Color;
 | 
			
		||||
import java.awt.Font;
 | 
			
		||||
import java.util.*;
 | 
			
		||||
 | 
			
		||||
import javax.swing.JFrame;
 | 
			
		||||
import javax.swing.JLabel;
 | 
			
		||||
import javax.swing.JButton;
 | 
			
		||||
import javax.swing.JComboBox;
 | 
			
		||||
import javax.swing.JPanel;
 | 
			
		||||
import javax.swing.JScrollPane;
 | 
			
		||||
import javax.swing.JTable;
 | 
			
		||||
import javax.swing.table.DefaultTableModel;
 | 
			
		||||
import javax.swing.UIManager;
 | 
			
		||||
import java.awt.SystemColor;
 | 
			
		||||
 | 
			
		||||
public class GUI_History {
 | 
			
		||||
	
 | 
			
		||||
	private List<State> states;
 | 
			
		||||
	private State selectedState;
 | 
			
		||||
	private ArrayList<Campaign> listOfCampaigns;
 | 
			
		||||
	private ArrayList<Vehicle> listOfVehicles;
 | 
			
		||||
	private ArrayList<Campaign>[] campPerDistrict;
 | 
			
		||||
	private Route[] stdRoutes;
 | 
			
		||||
	private Street[] stdStreet;
 | 
			
		||||
	private Date currenttimeManager;
 | 
			
		||||
	private JFrame frame;
 | 
			
		||||
	private JTable streetTable;
 | 
			
		||||
	private JTable districtTable;
 | 
			
		||||
	private JLabel lblDate;
 | 
			
		||||
	private JLabel lblDestination;
 | 
			
		||||
	private JLabel lblNumOfBuses;
 | 
			
		||||
	private JLabel lblNumOfDonebuses;
 | 
			
		||||
	private JLabel lblMaximumTripValue;
 | 
			
		||||
	private JLabel lblMinimumTripValue;
 | 
			
		||||
    private JLabel lblBusesArrivedInTheLastHourValue;
 | 
			
		||||
    private JLabel lblAverageTripForLastHourValue;
 | 
			
		||||
	private JLabel lblAverageTimeForTheTrip;
 | 
			
		||||
	private Object[][] streetData;
 | 
			
		||||
	private String[] streetColNames = {"Street Name", "Street Load %", "Total", "Buses",
 | 
			
		||||
										"Local Vehicles","Avg. Time"};
 | 
			
		||||
	private String[] districtColNames = {"District", "Campaigns", "Busses", "Arrival %",
 | 
			
		||||
			"Avg. Time", "Best time to Arafat", "Best time to District"};
 | 
			
		||||
 | 
			
		||||
	public GUI_History(List<State> states) {
 | 
			
		||||
		this.states = states;
 | 
			
		||||
		makeFrame();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private void makeFrame() {
 | 
			
		||||
		setData(states.get(0));
 | 
			
		||||
		frame = new JFrame("History");
 | 
			
		||||
		frame.setBounds(200, 150, 1386, 731);
 | 
			
		||||
		frame.setLocationRelativeTo(null);
 | 
			
		||||
		frame.getContentPane().setBackground(new Color(50,50,50));
 | 
			
		||||
		frame.getContentPane().setForeground(new Color(0, 0, 0));
 | 
			
		||||
		frame.getContentPane().setLayout(null);
 | 
			
		||||
		frame.revalidate();
 | 
			
		||||
		frame.setAutoRequestFocus(false);
 | 
			
		||||
		frame.setVisible(true);
 | 
			
		||||
		frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
 | 
			
		||||
		
 | 
			
		||||
		
 | 
			
		||||
		streetData = new Object[stdStreet.length][6];
 | 
			
		||||
		for (int i = 0; i < stdStreet.length; i++) {
 | 
			
		||||
			streetData[i][0] = stdStreet[i].getName().name();
 | 
			
		||||
			streetData[i][1] = stdStreet[i].getPercentRemainingCapacity();
 | 
			
		||||
			streetData[i][2] = stdStreet[i].getVehicles().size();
 | 
			
		||||
			streetData[i][3] = stdStreet[i].getNumberOfBuses();
 | 
			
		||||
			streetData[i][4] = stdStreet[i].getNumberOfLocalCars();
 | 
			
		||||
			streetData[i][5] = MakkahCity.avgTimeOnStreet(stdStreet[i]);
 | 
			
		||||
		}
 | 
			
		||||
		//District data
 | 
			
		||||
		Object[][] districtData = new Object[campPerDistrict.length][7];
 | 
			
		||||
 | 
			
		||||
		
 | 
			
		||||
		for (int i = 0; i < campPerDistrict.length; i++) {
 | 
			
		||||
			districtData[i][0] = campPerDistrict[i].get(0).getHotelDistrict().name();
 | 
			
		||||
			districtData[i][1] = campPerDistrict[i].size();
 | 
			
		||||
			districtData[i][2] = MakkahCity.busesInDistrict(District.values()[i]);
 | 
			
		||||
			districtData[i][3] = MakkahCity.getPercentArrival(District.values()[i]);
 | 
			
		||||
			districtData[i][4] = MakkahCity.getAvgTimeOfTrip(District.values()[i]);
 | 
			
		||||
			districtData[i][5] = MakkahCity.getShortestRoute(campPerDistrict[i].get(0), Mashier.ARAFAT).getFastestTimeOfTravel(new Bus());
 | 
			
		||||
			districtData[i][6] = MakkahCity.getShortestRoute(campPerDistrict[i].get(0), Mashier.MINA).getFastestTimeOfTravel(new Bus());
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		//tables
 | 
			
		||||
		
 | 
			
		||||
		//Street table
 | 
			
		||||
		streetTable = new JTable(streetData,streetColNames);
 | 
			
		||||
		streetTable.setEnabled(false);
 | 
			
		||||
		DefaultTableModel model = new DefaultTableModel();
 | 
			
		||||
		model.setColumnIdentifiers(streetColNames);
 | 
			
		||||
		streetTable.getTableHeader().setBackground(new Color(17,17,17));
 | 
			
		||||
		streetTable.getTableHeader().setForeground(Color.WHITE);
 | 
			
		||||
		streetTable.getTableHeader().setFont(new Font("Rockwell", Font.PLAIN, 18));
 | 
			
		||||
		streetTable.setBackground(new Color(17,17,17));
 | 
			
		||||
		streetTable.setForeground(Color.white);
 | 
			
		||||
		streetTable.setSelectionBackground(Color.RED);
 | 
			
		||||
		streetTable.setGridColor(new Color(102, 102, 102));
 | 
			
		||||
		streetTable.setSelectionForeground(Color.white);
 | 
			
		||||
		streetTable.setFont(new Font("Rockwell", Font.PLAIN, 18));
 | 
			
		||||
		streetTable.setRowHeight(25);
 | 
			
		||||
		streetTable.setAutoCreateRowSorter(true);
 | 
			
		||||
		JScrollPane streetScroll = new JScrollPane(streetTable);
 | 
			
		||||
		streetScroll.setBounds(30,75,1140,329);
 | 
			
		||||
		frame.getContentPane().add(streetScroll);
 | 
			
		||||
		
 | 
			
		||||
		//District table
 | 
			
		||||
		districtTable = new JTable(districtData,districtColNames);
 | 
			
		||||
		districtTable.setEnabled(false);
 | 
			
		||||
		districtTable.setForeground(new Color(255, 255, 255));
 | 
			
		||||
		districtTable.getTableHeader().setFont(new Font("Rockwell", Font.PLAIN, 18));
 | 
			
		||||
		districtTable.getTableHeader().setBackground(new Color(17,17,17));
 | 
			
		||||
		districtTable.getTableHeader().setForeground(Color.WHITE);
 | 
			
		||||
		districtTable.setBackground(new Color(17,17,17));
 | 
			
		||||
		districtTable.setSelectionBackground(Color.RED);
 | 
			
		||||
		model.setColumnIdentifiers(districtColNames);
 | 
			
		||||
		districtTable.setSelectionForeground(Color.white);
 | 
			
		||||
		districtTable.setFont(new Font("Rockwell", Font.PLAIN, 18));
 | 
			
		||||
		districtTable.setGridColor(new Color(102, 102, 102));
 | 
			
		||||
		JScrollPane districtScroll = new JScrollPane(districtTable);
 | 
			
		||||
		districtScroll.setEnabled(false);
 | 
			
		||||
		districtTable.setAutoCreateRowSorter(true);
 | 
			
		||||
		districtTable.setRowHeight(25);
 | 
			
		||||
		districtTable.revalidate();
 | 
			
		||||
		districtScroll.setBounds(30,452,1140,105);
 | 
			
		||||
		frame.getContentPane().add(districtScroll);
 | 
			
		||||
		
 | 
			
		||||
		JLabel lblStreets = new JLabel("Streets");
 | 
			
		||||
		lblStreets.setFont(new Font("Rockwell", Font.PLAIN, 24));
 | 
			
		||||
		lblStreets.setForeground(new Color(255, 255, 255));
 | 
			
		||||
		lblStreets.setBounds(30, 44, 208, 30);
 | 
			
		||||
		frame.getContentPane().add(lblStreets);
 | 
			
		||||
		
 | 
			
		||||
		JLabel lblDistrict = new JLabel("District");
 | 
			
		||||
		lblDistrict.setFont(new Font("Rockwell", Font.PLAIN, 24));
 | 
			
		||||
		lblDistrict.setForeground(new Color(255, 255, 255));
 | 
			
		||||
		lblDistrict.setBounds(30, 425, 166, 29);
 | 
			
		||||
		frame.getContentPane().add(lblDistrict);
 | 
			
		||||
		
 | 
			
		||||
		JLabel lblTime = new JLabel("Time:");
 | 
			
		||||
		lblTime.setFont(new Font("Rockwell", Font.PLAIN, 16));
 | 
			
		||||
		lblTime.setForeground(new Color(255, 255, 255));
 | 
			
		||||
		lblTime.setBounds(50, 11, 72, 14);
 | 
			
		||||
		frame.getContentPane().add(lblTime);
 | 
			
		||||
		
 | 
			
		||||
		JLabel lblStatus = new JLabel("Status:");
 | 
			
		||||
		lblStatus.setForeground(new Color(255, 255, 255));
 | 
			
		||||
		lblStatus.setFont(new Font("Rockwell", Font.PLAIN, 16));
 | 
			
		||||
		lblStatus.setBounds(423, 9, 72, 18);
 | 
			
		||||
		frame.getContentPane().add(lblStatus);
 | 
			
		||||
		
 | 
			
		||||
		lblDestination = new JLabel();
 | 
			
		||||
		lblDestination.setForeground(new Color(255, 255, 255));
 | 
			
		||||
		lblDestination.setFont(new Font("Rockwell", Font.PLAIN, 16));
 | 
			
		||||
		lblDestination.setBounds(477, 9, 184, 18);
 | 
			
		||||
		frame.getContentPane().add(lblDestination);
 | 
			
		||||
		
 | 
			
		||||
		lblDate = new JLabel(currenttimeManager.toString());
 | 
			
		||||
		lblDate.setFont(new Font("Rockwell", Font.PLAIN, 16));
 | 
			
		||||
		lblDate.setForeground(Color.WHITE);
 | 
			
		||||
		lblDate.setBounds(100, 8, 326, 21);
 | 
			
		||||
		frame.getContentPane().add(lblDate);
 | 
			
		||||
		
 | 
			
		||||
		JLabel lblBuses = new JLabel("Buses: ");
 | 
			
		||||
		lblBuses.setFont(new Font("Rockwell", Font.PLAIN, 16));
 | 
			
		||||
		lblBuses.setForeground(new Color(255, 255, 255));
 | 
			
		||||
		lblBuses.setBackground(new Color(192, 192, 192));
 | 
			
		||||
		lblBuses.setBounds(30, 578, 56, 14);
 | 
			
		||||
		frame.getContentPane().add(lblBuses);
 | 
			
		||||
		
 | 
			
		||||
		lblNumOfBuses = new JLabel();
 | 
			
		||||
		lblNumOfBuses.setText("0");
 | 
			
		||||
		lblNumOfBuses.setBackground(new Color(0, 0, 0));
 | 
			
		||||
		lblNumOfBuses.setForeground(new Color(255, 255, 255));
 | 
			
		||||
		lblNumOfBuses.setFont(new Font("Rockwell", Font.PLAIN, 16));
 | 
			
		||||
		lblNumOfBuses.setBounds(79, 579, 90, 12);
 | 
			
		||||
		frame.getContentPane().add(lblNumOfBuses);
 | 
			
		||||
		
 | 
			
		||||
		JLabel lblBusesDone = new JLabel("Buses Done:");
 | 
			
		||||
		lblBusesDone.setForeground(new Color(255, 255, 255));
 | 
			
		||||
		lblBusesDone.setFont(new Font("Rockwell", Font.PLAIN, 16));
 | 
			
		||||
		lblBusesDone.setBounds(169, 579, 101, 12);
 | 
			
		||||
		frame.getContentPane().add(lblBusesDone);
 | 
			
		||||
		
 | 
			
		||||
		lblNumOfDonebuses = new JLabel();
 | 
			
		||||
		lblNumOfDonebuses.setText("0");
 | 
			
		||||
		lblNumOfDonebuses.setForeground(new Color(255, 255, 255));
 | 
			
		||||
		lblNumOfDonebuses.setFont(new Font("Rockwell", Font.PLAIN, 16));
 | 
			
		||||
		lblNumOfDonebuses.setBounds(259, 577, 80, 16);
 | 
			
		||||
		frame.getContentPane().add(lblNumOfDonebuses);
 | 
			
		||||
		
 | 
			
		||||
		JLabel lblMaximumTrip = new JLabel("Maximum Trip:");
 | 
			
		||||
		lblMaximumTrip.setFont(new Font("Rockwell", Font.PLAIN, 16));
 | 
			
		||||
		lblMaximumTrip.setForeground(new Color(255, 255, 255));
 | 
			
		||||
		lblMaximumTrip.setBounds(30, 619, 112, 22);
 | 
			
		||||
		frame.getContentPane().add(lblMaximumTrip);
 | 
			
		||||
		
 | 
			
		||||
		lblMaximumTripValue = new JLabel();
 | 
			
		||||
		lblMaximumTripValue.setText("-:--");
 | 
			
		||||
		lblMaximumTripValue.setForeground(new Color(255, 255, 255));
 | 
			
		||||
		lblMaximumTripValue.setFont(new Font("Rockwell", Font.PLAIN, 16));
 | 
			
		||||
		lblMaximumTripValue.setBounds(150, 621, 46, 18);
 | 
			
		||||
		frame.getContentPane().add(lblMaximumTripValue);
 | 
			
		||||
		
 | 
			
		||||
		JLabel lblMinimumTrip = new JLabel("MinimumTrip:");
 | 
			
		||||
		lblMinimumTrip.setFont(new Font("Rockwell", Font.PLAIN, 16));
 | 
			
		||||
		lblMinimumTrip.setForeground(Color.WHITE);
 | 
			
		||||
		lblMinimumTrip.setBounds(30, 655, 112, 18);
 | 
			
		||||
		frame.getContentPane().add(lblMinimumTrip);
 | 
			
		||||
		
 | 
			
		||||
		lblMinimumTripValue = new JLabel("-:--");
 | 
			
		||||
		lblMinimumTripValue.setForeground(Color.WHITE);
 | 
			
		||||
		lblMinimumTripValue.setFont(new Font("Rockwell", Font.PLAIN, 16));
 | 
			
		||||
		lblMinimumTripValue.setBounds(139, 657, 46, 14);
 | 
			
		||||
		frame.getContentPane().add(lblMinimumTripValue);
 | 
			
		||||
		
 | 
			
		||||
		JLabel lblBusesArrivedInTheLastHour = new JLabel("Buses Arrived In The Last Hour:");
 | 
			
		||||
		lblBusesArrivedInTheLastHour.setForeground(Color.WHITE);
 | 
			
		||||
		lblBusesArrivedInTheLastHour.setFont(new Font("Rockwell", Font.PLAIN, 16));
 | 
			
		||||
		lblBusesArrivedInTheLastHour.setBounds(360, 578, 237, 14);
 | 
			
		||||
		frame.getContentPane().add(lblBusesArrivedInTheLastHour);
 | 
			
		||||
		
 | 
			
		||||
		lblBusesArrivedInTheLastHourValue = new JLabel();
 | 
			
		||||
		lblBusesArrivedInTheLastHourValue.setText("0");
 | 
			
		||||
		lblBusesArrivedInTheLastHourValue.setForeground(Color.WHITE);
 | 
			
		||||
		lblBusesArrivedInTheLastHourValue.setFont(new Font("Rockwell", Font.PLAIN, 16));
 | 
			
		||||
		lblBusesArrivedInTheLastHourValue.setBounds(594, 578, 90, 14);
 | 
			
		||||
		frame.getContentPane().add(lblBusesArrivedInTheLastHourValue);
 | 
			
		||||
		
 | 
			
		||||
		JLabel lblAverageTripForLastHour = new JLabel("Average Trip For Last Hour:");
 | 
			
		||||
		lblAverageTripForLastHour.setForeground(Color.WHITE);
 | 
			
		||||
		lblAverageTripForLastHour.setFont(new Font("Rockwell", Font.PLAIN, 16));
 | 
			
		||||
		lblAverageTripForLastHour.setBackground(Color.BLACK);
 | 
			
		||||
		lblAverageTripForLastHour.setBounds(206, 621, 208, 18);
 | 
			
		||||
		frame.getContentPane().add(lblAverageTripForLastHour);
 | 
			
		||||
		
 | 
			
		||||
		lblAverageTripForLastHourValue = new JLabel("(No Arrivals) In Last Hour");
 | 
			
		||||
		lblAverageTripForLastHourValue.setForeground(Color.WHITE);
 | 
			
		||||
		lblAverageTripForLastHourValue.setFont(new Font("Rockwell", Font.PLAIN, 16));
 | 
			
		||||
		lblAverageTripForLastHourValue.setBounds(423, 621, 216, 18);
 | 
			
		||||
		frame.getContentPane().add(lblAverageTripForLastHourValue);
 | 
			
		||||
		
 | 
			
		||||
		JLabel lblAvgTime = new JLabel("Average Time For The Trip:");
 | 
			
		||||
		lblAvgTime.setForeground(Color.WHITE);
 | 
			
		||||
		lblAvgTime.setFont(new Font("Rockwell", Font.PLAIN, 16));
 | 
			
		||||
		lblAvgTime.setBounds(206, 650, 208, 29);
 | 
			
		||||
		frame.getContentPane().add(lblAvgTime);
 | 
			
		||||
		
 | 
			
		||||
		lblAverageTimeForTheTrip = new JLabel("-:--");
 | 
			
		||||
		lblAverageTimeForTheTrip.setForeground(Color.WHITE);
 | 
			
		||||
		lblAverageTimeForTheTrip.setFont(new Font("Rockwell", Font.PLAIN, 16));
 | 
			
		||||
		lblAverageTimeForTheTrip.setBounds(423, 657, 101, 14);
 | 
			
		||||
		frame.getContentPane().add(lblAverageTimeForTheTrip);
 | 
			
		||||
		
 | 
			
		||||
		JButton btnViewRoutes = new JButton("View Routes");
 | 
			
		||||
		btnViewRoutes.setBounds(1195, 75, 166, 30);
 | 
			
		||||
		btnViewRoutes.setFont(new Font("Rockwell", Font.PLAIN, 16));
 | 
			
		||||
		btnViewRoutes.setBackground(new Color(9,9,9));
 | 
			
		||||
		btnViewRoutes.setForeground(Color.white);
 | 
			
		||||
		btnViewRoutes.addActionListener(e -> {
 | 
			
		||||
			GUI_ViewRoute r = new GUI_ViewRoute(stdRoutes ,listOfCampaigns, currenttimeManager);
 | 
			
		||||
		});
 | 
			
		||||
		frame.getContentPane().add(btnViewRoutes);
 | 
			
		||||
		
 | 
			
		||||
		JButton btnViewBuses = new JButton("View Buses");
 | 
			
		||||
		btnViewBuses.setBounds(1195, 130, 166, 30);
 | 
			
		||||
		btnViewBuses.setFont(new Font("Rockwell", Font.PLAIN, 16));
 | 
			
		||||
		btnViewBuses.setBackground(new Color(9,9,9));
 | 
			
		||||
		btnViewBuses.setForeground(Color.white);
 | 
			
		||||
		btnViewBuses.addActionListener(e -> {
 | 
			
		||||
			GUI_ViewBuses t =  new GUI_ViewBuses(listOfCampaigns , currenttimeManager);
 | 
			
		||||
		});
 | 
			
		||||
		frame.getContentPane().add(btnViewBuses);
 | 
			
		||||
		
 | 
			
		||||
		JButton btnViewStreet = new JButton("View Street");
 | 
			
		||||
		btnViewStreet.setBounds(1195, 185, 166, 29);
 | 
			
		||||
		btnViewStreet.setFont(new Font("Rockwell", Font.PLAIN, 16));
 | 
			
		||||
		btnViewStreet.setBackground(new Color(9,9,9));
 | 
			
		||||
		btnViewStreet.setForeground(Color.white);
 | 
			
		||||
		btnViewStreet.addActionListener(e -> {
 | 
			
		||||
			GUI_ViewStreet t =  new GUI_ViewStreet(stdStreet,currenttimeManager);
 | 
			
		||||
		});
 | 
			
		||||
		frame.getContentPane().add(btnViewStreet);
 | 
			
		||||
		
 | 
			
		||||
		JComboBox comboBox = new JComboBox<Date>();
 | 
			
		||||
		comboBox.setBackground(new Color(150, 150 , 150));
 | 
			
		||||
		comboBox.setBounds(1143, 11, 217, 33);
 | 
			
		||||
		for (State state : states) {
 | 
			
		||||
			comboBox.addItem(state.getStateTime());
 | 
			
		||||
		}
 | 
			
		||||
		comboBox.addActionListener(e ->{
 | 
			
		||||
			setData(states.get(comboBox.getSelectedIndex()));
 | 
			
		||||
			updateFrame();
 | 
			
		||||
		});
 | 
			
		||||
		frame.getContentPane().add(comboBox);
 | 
			
		||||
		updateFrame();
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public void setData(State state) {
 | 
			
		||||
		listOfCampaigns = state.getListOfCampaigns();
 | 
			
		||||
		listOfVehicles = state.getListOfVehicles();
 | 
			
		||||
		campPerDistrict = state.getCampPerDistrict();
 | 
			
		||||
		stdRoutes = state.getStdRoutes();
 | 
			
		||||
		stdStreet = state.getStdStreet();
 | 
			
		||||
		currenttimeManager = state.getStateTime();
 | 
			
		||||
		selectedState = state;
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public void updateFrame() {
 | 
			
		||||
			streetData = new Object[stdStreet.length][6];
 | 
			
		||||
			for (int i = 0; i < stdStreet.length; i++) {
 | 
			
		||||
				streetData[i][0] = stdStreet[i].getName().name();
 | 
			
		||||
				streetData[i][1] = stdStreet[i].getPercentRemainingCapacity();
 | 
			
		||||
				streetData[i][2] = stdStreet[i].getVehicles().size();
 | 
			
		||||
				streetData[i][3] = stdStreet[i].getNumberOfBuses();
 | 
			
		||||
				streetData[i][4] = stdStreet[i].getNumberOfLocalCars();
 | 
			
		||||
				streetData[i][5] = avgTimeOnStreet(stdStreet[i]);
 | 
			
		||||
			}
 | 
			
		||||
			streetTable.setModel(new DefaultTableModel(streetData ,streetColNames));
 | 
			
		||||
			
 | 
			
		||||
			Object[][] districtData = new Object[campPerDistrict.length][7];
 | 
			
		||||
			for (int i = 0; i < campPerDistrict.length; i++) {
 | 
			
		||||
				districtData[i][0] = campPerDistrict[i].get(0).getHotelDistrict().name();
 | 
			
		||||
				districtData[i][1] = campPerDistrict[i].size();
 | 
			
		||||
				districtData[i][2] = busesInDistrict(District.values()[i]);
 | 
			
		||||
				districtData[i][3] = getPercentArrival(District.values()[i]);
 | 
			
		||||
				districtData[i][4] = getAvgTimeOfTrip(District.values()[i]);
 | 
			
		||||
				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());
 | 
			
		||||
			}
 | 
			
		||||
			districtTable.setModel(new DefaultTableModel(districtData, districtColNames));
 | 
			
		||||
			lblDate.setText(currenttimeManager.toString());
 | 
			
		||||
			
 | 
			
		||||
			 String status = "";
 | 
			
		||||
			 if (currenttimeManager.getDay() == 9) {
 | 
			
		||||
				 status = "Heading to Arafat";
 | 
			
		||||
			 }
 | 
			
		||||
				else{
 | 
			
		||||
					status = "Heading to Hotels";
 | 
			
		||||
				}
 | 
			
		||||
			 	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());
 | 
			
		||||
			lblNumOfDonebuses.setText(numOfdoneBuses);
 | 
			
		||||
			
 | 
			
		||||
			String NumberOfBussPerHour = String.format("%d", getNumberOfArrivedBussesPerHour());
 | 
			
		||||
			lblBusesArrivedInTheLastHourValue.setText(NumberOfBussPerHour);
 | 
			
		||||
			
 | 
			
		||||
			lblAverageTripForLastHourValue.setText(avgTimeOfTrip());
 | 
			
		||||
			lblAverageTimeForTheTrip.setText(getAvgTripForAllDis());
 | 
			
		||||
			lblMaximumTripValue.setText(selectedState.getMaxTrip());
 | 
			
		||||
			lblMinimumTripValue.setText(selectedState.getMinTrip());
 | 
			
		||||
		 }
 | 
			
		||||
 | 
			
		||||
	//Methods
 | 
			
		||||
	public String avgTimeOnStreet(Street street) {
 | 
			
		||||
		int sum = 0;
 | 
			
		||||
		int counter = 1;
 | 
			
		||||
		for (Campaign campaign : listOfCampaigns)
 | 
			
		||||
			for (Vehicle vehicle : campaign.getArrivedVehicles())
 | 
			
		||||
				if (vehicle.hasCrossedStreet(street)){
 | 
			
		||||
					sum += vehicle.getTimeOnStreet(street);
 | 
			
		||||
					counter++;
 | 
			
		||||
				}
 | 
			
		||||
		sum /= counter;
 | 
			
		||||
		int hours = sum / 60;
 | 
			
		||||
		int minutes = sum % 60;
 | 
			
		||||
		if (hours == 0 && minutes == 0) return street.getFastestTimeOfTravel(new Bus());
 | 
			
		||||
		return String.format("%02d:%02d", hours, minutes);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private int busesInDistrict(District district){
 | 
			
		||||
		int buses = 0;
 | 
			
		||||
		for (Campaign campaign : campPerDistrict[district.ordinal()]){
 | 
			
		||||
			buses += campaign.getNumberOfBusses();
 | 
			
		||||
		}
 | 
			
		||||
		return buses;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private int getPercentArrival(District district) {
 | 
			
		||||
		int sum = 0;
 | 
			
		||||
		for (Campaign campaign : campPerDistrict[district.ordinal()]) {
 | 
			
		||||
			sum += campaign.getPercentArrived();
 | 
			
		||||
		}
 | 
			
		||||
		return sum/campPerDistrict[district.ordinal()].size();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private String getAvgTimeOfTrip(District district){
 | 
			
		||||
		int sum = 0;
 | 
			
		||||
		int counter = 1;
 | 
			
		||||
		for (Campaign campaign : campPerDistrict[district.ordinal()]) {
 | 
			
		||||
			for (Vehicle vehicle : campaign.getVehicles()) {
 | 
			
		||||
				if (vehicle.isArrivedToDest()) {
 | 
			
		||||
					long minutes = (vehicle.getTimeOfArrival().getTime() - vehicle.getTimeStartedMoving().getTime())/60000;
 | 
			
		||||
					sum+= minutes;
 | 
			
		||||
					counter++;
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		sum = sum /counter;
 | 
			
		||||
		int hours = sum / 60;
 | 
			
		||||
		int minutes = sum % 60;
 | 
			
		||||
		if (hours == 0 && minutes == 0) return " n/a";
 | 
			
		||||
		return String.format("%2d:%02d", hours,minutes);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private Route getShortestRoute(Campaign campaign, Mashier mashier) {
 | 
			
		||||
		Route[] routes = getRoutesToDistrict(campaign.getHotelDistrict());
 | 
			
		||||
		Route route = null;
 | 
			
		||||
		double min = Double.MAX_VALUE;
 | 
			
		||||
		for (Route r : routes) {
 | 
			
		||||
			if (r.getMashier() == mashier){
 | 
			
		||||
				if (r.getTotalLength() < min) {
 | 
			
		||||
					min = r.getTotalLength();
 | 
			
		||||
					route = r;
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		return route;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private Route[] getRoutesToDistrict(District district) {
 | 
			
		||||
		ArrayList<Route> routes = new ArrayList<>();
 | 
			
		||||
		for (Route route : stdRoutes) {
 | 
			
		||||
			if (route.getHotelArea() == district) {
 | 
			
		||||
				routes.add(route);
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		Route[] routesArray = new Route[routes.size()];
 | 
			
		||||
		return routes.toArray(routesArray);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public int getNumberOfArrivedBusses() {
 | 
			
		||||
		int num = 0;
 | 
			
		||||
		for (Campaign campaign : listOfCampaigns) {
 | 
			
		||||
			for (Vehicle vehicle : campaign.getVehicles()){
 | 
			
		||||
				if (vehicle instanceof  Bus &&
 | 
			
		||||
						vehicle.isArrivedToDest()) num++;
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		return num;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public int getNumberOfArrivedBussesPerHour() {
 | 
			
		||||
		Calendar now = new GregorianCalendar();
 | 
			
		||||
		now.setTime(currenttimeManager);
 | 
			
		||||
		Calendar from = (GregorianCalendar)now.clone();
 | 
			
		||||
		from.roll(Calendar.HOUR, -1);
 | 
			
		||||
		int num = 0;
 | 
			
		||||
		for (Campaign campaign : listOfCampaigns){
 | 
			
		||||
			for (Vehicle bus : campaign.getVehicles()){
 | 
			
		||||
				if (bus.isArrivedToDest() && bus.getTimeOfArrival().before(now.getTime())
 | 
			
		||||
						&& bus.getTimeOfArrival().after(from.getTime())) {
 | 
			
		||||
					num++;
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		return num;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public String avgTimeOfTrip() {
 | 
			
		||||
		//TODO: does output diff value even after all have arrived.
 | 
			
		||||
		Calendar now = new GregorianCalendar();
 | 
			
		||||
		now.setTime(currenttimeManager);
 | 
			
		||||
		Calendar from = (GregorianCalendar)now.clone();
 | 
			
		||||
		from.roll(Calendar.HOUR, -1);
 | 
			
		||||
		int counter = 1;
 | 
			
		||||
		int sum = 0;
 | 
			
		||||
		for (Campaign campaign : listOfCampaigns){
 | 
			
		||||
			for (Vehicle bus : campaign.getVehicles()){
 | 
			
		||||
				if (bus.isArrivedToDest() && bus.getTimeOfArrival().before(now.getTime())
 | 
			
		||||
						&& bus.getTimeOfArrival().after(from.getTime())) {
 | 
			
		||||
					long minutes = (bus.getTimeOfArrival().getTime() - bus.getTimeStartedMoving().getTime())/60000;
 | 
			
		||||
					sum+= minutes;
 | 
			
		||||
					counter++;
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		sum = sum /counter;
 | 
			
		||||
		int hours = sum / 60;
 | 
			
		||||
		int minutes = sum % 60;
 | 
			
		||||
		if (hours == 0 && minutes == 0) return "(No Arrivals) In Last Hour";
 | 
			
		||||
		return String.format("%2d:%02d", hours, minutes);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public 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);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
@ -1,237 +0,0 @@
 | 
			
		||||
import java.awt.Color;
 | 
			
		||||
import java.awt.Font;
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.Date;
 | 
			
		||||
 | 
			
		||||
import javax.swing.JFrame;
 | 
			
		||||
import javax.swing.JLabel;
 | 
			
		||||
import javax.swing.JScrollPane;
 | 
			
		||||
import javax.swing.JTable;
 | 
			
		||||
import javax.swing.table.DefaultTableModel;
 | 
			
		||||
 | 
			
		||||
public class GUI_Report {
 | 
			
		||||
	JFrame frame;
 | 
			
		||||
	private static ArrayList<Campaign> listOfCampaigns;
 | 
			
		||||
	private static Route[] stdRoutes;
 | 
			
		||||
	private JTable streetTable;
 | 
			
		||||
	private JTable districtTable;
 | 
			
		||||
	private Street[] stdStreet;
 | 
			
		||||
	private Date currenttimeManager;
 | 
			
		||||
	private static ArrayList<Campaign>[] campPerDistrict;
 | 
			
		||||
	private  String[] streetColNames = {"Street Name", "Street Load %", "Total","Buses","Local Vehicles","Avg. Time"};
 | 
			
		||||
	private  String[] districtColNames = {"District", "Campaigns", "Busses", "Arrival %","Avg. Time", "Best time to Arafat", "Best time to District"};
 | 
			
		||||
	private  Object[][] streetData;
 | 
			
		||||
	private  Object[][] districtData;
 | 
			
		||||
	private JLabel lblDate;
 | 
			
		||||
	
 | 
			
		||||
	public GUI_Report(ArrayList<Campaign> listOfCampaigns, Route[] stdRoutes, Street[] stdStreet, ArrayList<Campaign>[] campPerDistrict, Date currenttimeManager) {
 | 
			
		||||
		this.listOfCampaigns = listOfCampaigns;
 | 
			
		||||
		this.stdRoutes = stdRoutes;
 | 
			
		||||
		this.stdStreet = stdStreet;
 | 
			
		||||
		this.campPerDistrict = campPerDistrict;
 | 
			
		||||
		this.currenttimeManager = currenttimeManager;
 | 
			
		||||
		makeFrame();
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
 | 
			
		||||
	private void makeFrame() {
 | 
			
		||||
		frame = new JFrame("Report");
 | 
			
		||||
		
 | 
			
		||||
		//Street data
 | 
			
		||||
		streetData = new Object[stdStreet.length][6];
 | 
			
		||||
		
 | 
			
		||||
		for (int i = 0; i < stdStreet.length; i++) {
 | 
			
		||||
			streetData[i][0] = stdStreet[i].getName().name();
 | 
			
		||||
			streetData[i][1] = stdStreet[i].getPercentRemainingCapacity();
 | 
			
		||||
			streetData[i][2] = stdStreet[i].getVehicles().size();
 | 
			
		||||
			streetData[i][3] = stdStreet[i].getNumberOfBuses();
 | 
			
		||||
			streetData[i][4] = stdStreet[i].getNumberOfLocalCars();
 | 
			
		||||
			streetData[i][5] = avgTimeOnStreet(stdStreet[i]);
 | 
			
		||||
		}
 | 
			
		||||
		DefaultTableModel model = new DefaultTableModel();
 | 
			
		||||
		model.setColumnIdentifiers(streetColNames);
 | 
			
		||||
		//district
 | 
			
		||||
		districtData = new Object[campPerDistrict.length][7];
 | 
			
		||||
		for (int i = 0; i < campPerDistrict.length; i++) {
 | 
			
		||||
			districtData[i][0] = campPerDistrict[i].get(0).getHotelDistrict().name();
 | 
			
		||||
			districtData[i][1] = campPerDistrict[i].size();
 | 
			
		||||
			districtData[i][2] = busesInDistrict(District.values()[i]);
 | 
			
		||||
			districtData[i][3] = getPercentArrival(District.values()[i]);
 | 
			
		||||
			districtData[i][4] = getAvgTimeOfTrip(District.values()[i]);
 | 
			
		||||
			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());
 | 
			
		||||
		}
 | 
			
		||||
			//tables
 | 
			
		||||
			
 | 
			
		||||
        	//Street table
 | 
			
		||||
			streetTable = new JTable(streetData,streetColNames);
 | 
			
		||||
			streetTable.setEnabled(false);
 | 
			
		||||
			streetTable.getTableHeader().setBackground(new Color(17,17,17));
 | 
			
		||||
			streetTable.getTableHeader().setForeground(Color.WHITE);
 | 
			
		||||
			streetTable.getTableHeader().setFont(new Font("Rockwell", Font.PLAIN, 18));
 | 
			
		||||
			streetTable.setBackground(new Color(17,17,17));
 | 
			
		||||
			streetTable.setForeground(Color.white);
 | 
			
		||||
			streetTable.setGridColor(new Color(102, 102, 102));
 | 
			
		||||
			streetTable.setSelectionForeground(Color.white);
 | 
			
		||||
			streetTable.setFont(new Font("Rockwell", Font.PLAIN, 18));
 | 
			
		||||
			streetTable.setRowHeight(20);
 | 
			
		||||
			streetTable.setAutoCreateRowSorter(true);
 | 
			
		||||
			JScrollPane streetScroll = new JScrollPane(streetTable);
 | 
			
		||||
			streetTable.getColumnModel().getColumn(0).setPreferredWidth(111);
 | 
			
		||||
			streetTable.getColumnModel().getColumn(1).setPreferredWidth(46);
 | 
			
		||||
			streetTable.getColumnModel().getColumn(2).setPreferredWidth(1);
 | 
			
		||||
			streetTable.getColumnModel().getColumn(3).setPreferredWidth(0);
 | 
			
		||||
			streetTable.getColumnModel().getColumn(4).setPreferredWidth(60);
 | 
			
		||||
			streetTable.getColumnModel().getColumn(5).setPreferredWidth(0);
 | 
			
		||||
			streetScroll.setBounds(10,75,809,269);
 | 
			
		||||
			
 | 
			
		||||
			//District table
 | 
			
		||||
			districtTable = new JTable(districtData,districtColNames);
 | 
			
		||||
			districtTable.setEnabled(false);
 | 
			
		||||
			districtTable.setForeground(new Color(255, 255, 255));
 | 
			
		||||
			districtTable.getTableHeader().setFont(new Font("Rockwell", Font.PLAIN, 18));
 | 
			
		||||
			districtTable.getTableHeader().setBackground(new Color(17,17,17));
 | 
			
		||||
			districtTable.getTableHeader().setForeground(Color.WHITE);
 | 
			
		||||
			districtTable.setBackground(new Color(17,17,17));
 | 
			
		||||
			districtTable.setSelectionBackground(Color.RED);
 | 
			
		||||
			model.setColumnIdentifiers(districtColNames);
 | 
			
		||||
			districtTable.setSelectionForeground(Color.white);
 | 
			
		||||
			districtTable.setFont(new Font("Rockwell", Font.PLAIN, 18));
 | 
			
		||||
			districtTable.setGridColor(new Color(102, 102, 102));
 | 
			
		||||
			JScrollPane districtScroll = new JScrollPane(districtTable);
 | 
			
		||||
			districtScroll.setEnabled(false);
 | 
			
		||||
			districtTable.setAutoCreateRowSorter(true);
 | 
			
		||||
			districtTable.getColumnModel().getColumn(0).setPreferredWidth(43);
 | 
			
		||||
			districtTable.getColumnModel().getColumn(1).setPreferredWidth(30);
 | 
			
		||||
			districtTable.getColumnModel().getColumn(2).setPreferredWidth(0);
 | 
			
		||||
			districtTable.getColumnModel().getColumn(3).setPreferredWidth(0);
 | 
			
		||||
			districtTable.getColumnModel().getColumn(4).setPreferredWidth(0);
 | 
			
		||||
			districtTable.getColumnModel().getColumn(5).setPreferredWidth(85);
 | 
			
		||||
			districtTable.getColumnModel().getColumn(6).setPreferredWidth(93);
 | 
			
		||||
			districtTable.setRowHeight(20);
 | 
			
		||||
			districtTable.revalidate();
 | 
			
		||||
			districtScroll.setBounds(10,395,809,89);
 | 
			
		||||
			
 | 
			
		||||
			//lbl
 | 
			
		||||
			
 | 
			
		||||
			JLabel lblTime = new JLabel("Time:");
 | 
			
		||||
			lblTime.setFont(new Font("Rockwell", Font.PLAIN, 16));
 | 
			
		||||
			lblTime.setForeground(new Color(255, 255, 255));
 | 
			
		||||
			lblTime.setBounds(50, 11, 72, 14);
 | 
			
		||||
			
 | 
			
		||||
			//Add Elements
 | 
			
		||||
			frame.getContentPane().add(streetScroll);
 | 
			
		||||
			frame.getContentPane().add(districtScroll);
 | 
			
		||||
			frame.getContentPane().setBackground(new Color(50,50,50));
 | 
			
		||||
			frame.getContentPane().setForeground(new Color(0, 0, 0));
 | 
			
		||||
			frame.setBounds(100,100,856,540);
 | 
			
		||||
			frame.getContentPane().setLayout(null);
 | 
			
		||||
			
 | 
			
		||||
			JLabel lblStreets = new JLabel("Streets");
 | 
			
		||||
			lblStreets.setForeground(Color.WHITE);
 | 
			
		||||
			lblStreets.setFont(new Font("Rockwell", Font.PLAIN, 24));
 | 
			
		||||
			lblStreets.setBounds(10, 34, 208, 30);
 | 
			
		||||
			frame.getContentPane().add(lblStreets);
 | 
			
		||||
			
 | 
			
		||||
			JLabel lblDistrict = new JLabel("District");
 | 
			
		||||
			lblDistrict.setForeground(Color.WHITE);
 | 
			
		||||
			lblDistrict.setFont(new Font("Rockwell", Font.PLAIN, 24));
 | 
			
		||||
			lblDistrict.setBounds(10, 355, 166, 29);
 | 
			
		||||
			frame.getContentPane().add(lblDistrict);
 | 
			
		||||
			
 | 
			
		||||
			JLabel lblTime_1 = new JLabel("Time:");
 | 
			
		||||
			lblTime_1.setForeground(Color.WHITE);
 | 
			
		||||
			lblTime_1.setFont(new Font("Rockwell", Font.PLAIN, 16));
 | 
			
		||||
			lblTime_1.setBounds(190, 21, 72, 14);
 | 
			
		||||
			frame.getContentPane().add(lblTime_1);
 | 
			
		||||
			
 | 
			
		||||
			lblDate = new JLabel(currenttimeManager.toString());
 | 
			
		||||
			lblDate.setForeground(Color.WHITE);
 | 
			
		||||
			lblDate.setFont(new Font("Rockwell", Font.PLAIN, 16));
 | 
			
		||||
			lblDate.setBounds(238, 18, 326, 21);
 | 
			
		||||
			frame.getContentPane().add(lblDate);
 | 
			
		||||
			frame.setLocationRelativeTo(null);
 | 
			
		||||
			frame.revalidate();
 | 
			
		||||
			frame.setLocation(100,150);
 | 
			
		||||
			frame.setAutoRequestFocus(false);
 | 
			
		||||
			frame.setVisible(true);
 | 
			
		||||
		
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	//Methods
 | 
			
		||||
	public static String avgTimeOnStreet(Street street) {
 | 
			
		||||
		int sum = 0;
 | 
			
		||||
		int counter = 1;
 | 
			
		||||
		for (Campaign campaign : listOfCampaigns)
 | 
			
		||||
			for (Vehicle vehicle : campaign.getArrivedVehicles())
 | 
			
		||||
				if (vehicle.hasCrossedStreet(street)){
 | 
			
		||||
					sum += vehicle.getTimeOnStreet(street);
 | 
			
		||||
					counter++;
 | 
			
		||||
				}
 | 
			
		||||
		sum /= counter;
 | 
			
		||||
		int hours = sum / 60;
 | 
			
		||||
		int minutes = sum % 60;
 | 
			
		||||
		if (hours == 0 && minutes == 0) return street.getFastestTimeOfTravel(new Bus());
 | 
			
		||||
		return String.format("%02d:%02d", hours, minutes);
 | 
			
		||||
	}
 | 
			
		||||
	private static int busesInDistrict(District district){
 | 
			
		||||
		int buses = 0;
 | 
			
		||||
		for (Campaign campaign : campPerDistrict[district.ordinal()]){
 | 
			
		||||
			buses += campaign.getNumberOfBusses();
 | 
			
		||||
		}
 | 
			
		||||
		return buses;
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	private static int getPercentArrival(District district) {
 | 
			
		||||
		int sum = 0;
 | 
			
		||||
		for (Campaign campaign : campPerDistrict[district.ordinal()]) {
 | 
			
		||||
			sum += campaign.getPercentArrived();
 | 
			
		||||
		}
 | 
			
		||||
		return sum/campPerDistrict[district.ordinal()].size();
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	private static String getAvgTimeOfTrip(District district){
 | 
			
		||||
		int sum = 0;
 | 
			
		||||
		int counter = 1;
 | 
			
		||||
		for (Campaign campaign : campPerDistrict[district.ordinal()]) {
 | 
			
		||||
			for (Vehicle vehicle : campaign.getVehicles()) {
 | 
			
		||||
				if (vehicle.isArrivedToDest()) {
 | 
			
		||||
					long minutes = (vehicle.getTimeOfArrival().getTime() - vehicle.getTimeStartedMoving().getTime())/60000;
 | 
			
		||||
					sum+= minutes;
 | 
			
		||||
					counter++;
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		sum = sum /counter;
 | 
			
		||||
		int hours = sum / 60;
 | 
			
		||||
		int minutes = sum % 60;
 | 
			
		||||
		if (hours == 0 && minutes == 0) return " n/a";
 | 
			
		||||
		return String.format("%2d:%02d", hours,minutes);
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	private static Route getShortestRoute(Campaign campaign, Mashier mashier) {
 | 
			
		||||
		Route[] routes = getRoutesToDistrict(campaign.getHotelDistrict());
 | 
			
		||||
		Route route = null;
 | 
			
		||||
		double min = Double.MAX_VALUE;
 | 
			
		||||
		for (Route r : routes) {
 | 
			
		||||
			if (r.getMashier() == mashier){
 | 
			
		||||
				if (r.getTotalLength() < min) {
 | 
			
		||||
					min = r.getTotalLength();
 | 
			
		||||
					route = r;
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		return route;
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	private static Route[] getRoutesToDistrict(District district) {
 | 
			
		||||
		ArrayList<Route> routes = new ArrayList<>();
 | 
			
		||||
		for (Route route : stdRoutes) {
 | 
			
		||||
			if (route.getHotelArea() == district) {
 | 
			
		||||
				routes.add(route);
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		Route[] routesArray = new Route[routes.size()];
 | 
			
		||||
		return routes.toArray(routesArray);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
@ -1,224 +0,0 @@
 | 
			
		||||
import java.awt.EventQueue;
 | 
			
		||||
import javax.swing.JFrame;
 | 
			
		||||
import javax.swing.JLabel;
 | 
			
		||||
import java.awt.Font;
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.Calendar;
 | 
			
		||||
import javax.swing.JScrollPane;
 | 
			
		||||
import javax.swing.JButton;
 | 
			
		||||
import java.awt.Color;
 | 
			
		||||
import java.util.Date;
 | 
			
		||||
import java.util.GregorianCalendar;
 | 
			
		||||
import javax.swing.table.DefaultTableModel;
 | 
			
		||||
import javax.swing.JTable;
 | 
			
		||||
import javax.swing.ListSelectionModel;
 | 
			
		||||
import javax.swing.JTextField;
 | 
			
		||||
import javax.swing.DropMode;
 | 
			
		||||
import javax.swing.JTextPane;
 | 
			
		||||
 | 
			
		||||
public class GUI_ViewBuses {
 | 
			
		||||
 | 
			
		||||
	private JFrame frame;
 | 
			
		||||
	private ArrayList<Vehicle> vehicles = new ArrayList<>();
 | 
			
		||||
	private ArrayList<Vehicle> vehiclesAlazizya = new ArrayList<>();
 | 
			
		||||
	private ArrayList<Vehicle> vehiclesAlhijra = new ArrayList<>();
 | 
			
		||||
	private ArrayList<Vehicle> vehiclesAlmansoor = new ArrayList<>();
 | 
			
		||||
	private Date currenttimeManager;
 | 
			
		||||
	private JTable table;
 | 
			
		||||
	private Object[][] busData;
 | 
			
		||||
	private String[] busColNames = {"ID", "Street", "location","Progress", "trip time",  "Arrive Time"};
 | 
			
		||||
	private JButton Alazizya;
 | 
			
		||||
	private JButton Alhijra;
 | 
			
		||||
	private JButton Almansoor;
 | 
			
		||||
	private JLabel lblTime;
 | 
			
		||||
	private JLabel lblDate;
 | 
			
		||||
	private JLabel lblStatus;
 | 
			
		||||
	private JLabel lblDestination;
 | 
			
		||||
	private JLabel lblDistrict;
 | 
			
		||||
	private JLabel lblDistrictValue;
 | 
			
		||||
	private JTextPane textPane;
 | 
			
		||||
	
 | 
			
		||||
	
 | 
			
		||||
	public GUI_ViewBuses(ArrayList<Campaign> campaign , Date currenttimeManager) {
 | 
			
		||||
		for (Campaign camp : campaign) {
 | 
			
		||||
			switch (camp.getHotelDistrict()) {
 | 
			
		||||
			case ALAZIZIYA:
 | 
			
		||||
				vehiclesAlazizya.add(camp.getVehicles().get(0));
 | 
			
		||||
				break;
 | 
			
		||||
			case ALHIJRA:
 | 
			
		||||
				vehiclesAlhijra.add(camp.getVehicles().get(0));
 | 
			
		||||
				break;
 | 
			
		||||
			case ALMANSOOR:
 | 
			
		||||
				vehiclesAlmansoor.add(camp.getVehicles().get(0));
 | 
			
		||||
				break;
 | 
			
		||||
			default:
 | 
			
		||||
				break;
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		this.currenttimeManager = currenttimeManager;
 | 
			
		||||
		makeFrame();
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	
 | 
			
		||||
	private void makeFrame() {
 | 
			
		||||
		frame = new JFrame("Buses");
 | 
			
		||||
		
 | 
			
		||||
		table = new JTable(busData,busColNames);
 | 
			
		||||
		table.setColumnSelectionAllowed(true);
 | 
			
		||||
		table.setCellSelectionEnabled(true);
 | 
			
		||||
		DefaultTableModel model = new DefaultTableModel();
 | 
			
		||||
		model.setColumnIdentifiers(busColNames);
 | 
			
		||||
		ListSelectionModel model2 = table.getSelectionModel();
 | 
			
		||||
		model2.addListSelectionListener(e -> {
 | 
			
		||||
				if (!model2.isSelectionEmpty()) {
 | 
			
		||||
				int row = model2.getMinSelectionIndex();
 | 
			
		||||
				textPane.setText(((Bus)vehicles.get(row)).toString());
 | 
			
		||||
			}
 | 
			
		||||
			});
 | 
			
		||||
		table.getTableHeader().setBackground(new Color(17,17,17));
 | 
			
		||||
		table.getTableHeader().setFont(new Font("Rockwell", Font.PLAIN, 18));
 | 
			
		||||
		table.getTableHeader().setForeground(Color.WHITE);
 | 
			
		||||
		table.setModel(new DefaultTableModel(busData ,busColNames));
 | 
			
		||||
		table.setBackground(new Color(17,17,17));
 | 
			
		||||
		table.setForeground(Color.WHITE);
 | 
			
		||||
		table.setGridColor(new Color(102, 102, 102));
 | 
			
		||||
		table.setFont(new Font("Rockwell", Font.PLAIN, 18));
 | 
			
		||||
		table.setRowHeight(25);
 | 
			
		||||
		table.setAutoCreateRowSorter(true);
 | 
			
		||||
		table.revalidate();
 | 
			
		||||
		
 | 
			
		||||
		JScrollPane scrollPane = new JScrollPane(table);
 | 
			
		||||
		scrollPane.getVerticalScrollBar().setBackground(new Color(17,17,17));
 | 
			
		||||
		scrollPane.setBounds(20, 24, 887, 236);
 | 
			
		||||
		
 | 
			
		||||
		frame.getContentPane().setBackground(new Color(50,50,50));
 | 
			
		||||
		frame.getContentPane().setForeground(new Color(0, 0, 0));
 | 
			
		||||
		frame.setBounds(100,100,972,454);
 | 
			
		||||
		frame.getContentPane().setLayout(null);
 | 
			
		||||
		frame.setLocationRelativeTo(null);
 | 
			
		||||
		frame.getContentPane().add(scrollPane);
 | 
			
		||||
		
 | 
			
		||||
		Alazizya = new JButton("Alazizya");
 | 
			
		||||
		Alazizya.setBackground(new Color(9,9,9));
 | 
			
		||||
		Alazizya.setFont(new Font("Rockwell", Font.PLAIN, 16));
 | 
			
		||||
		Alazizya.setForeground(Color.white);
 | 
			
		||||
		Alazizya.setBounds(20, 366, 116, 23);
 | 
			
		||||
		Alazizya.addActionListener(e -> {
 | 
			
		||||
			if (vehiclesAlazizya.get(0).getRoute() != null)
 | 
			
		||||
			updateVehicles(vehiclesAlazizya);
 | 
			
		||||
		});
 | 
			
		||||
		frame.getContentPane().add(Alazizya);
 | 
			
		||||
		
 | 
			
		||||
		Alhijra = new JButton("Alhijra");
 | 
			
		||||
		Alhijra.setBackground(new Color(9,9,9));
 | 
			
		||||
		Alhijra.setFont(new Font("Rockwell", Font.PLAIN, 16));
 | 
			
		||||
		Alhijra.setForeground(Color.white);
 | 
			
		||||
		Alhijra.setBounds(20, 269, 116, 23);
 | 
			
		||||
		Alhijra.addActionListener(e -> {
 | 
			
		||||
			if (vehiclesAlhijra.get(0).getRoute() != null)
 | 
			
		||||
			updateVehicles(vehiclesAlhijra);
 | 
			
		||||
		});
 | 
			
		||||
		frame.getContentPane().add(Alhijra);
 | 
			
		||||
		
 | 
			
		||||
		Almansoor = new JButton("Almansoor");
 | 
			
		||||
		Almansoor.setBackground(new Color(9,9,9));
 | 
			
		||||
		Almansoor.setFont(new Font("Rockwell", Font.PLAIN, 16));
 | 
			
		||||
		Almansoor.setForeground(Color.white);
 | 
			
		||||
		Almansoor.setBounds(20, 316, 116, 23);
 | 
			
		||||
		Almansoor.addActionListener(e -> {
 | 
			
		||||
			if (vehiclesAlmansoor.get(0).getRoute() != null)
 | 
			
		||||
			updateVehicles(vehiclesAlmansoor);
 | 
			
		||||
		});
 | 
			
		||||
		frame.getContentPane().add(Almansoor);
 | 
			
		||||
		
 | 
			
		||||
		lblTime = new JLabel("Time:");
 | 
			
		||||
		lblTime.setFont(new Font("Rockwell", Font.PLAIN, 16));
 | 
			
		||||
		lblTime.setForeground(new Color(255, 255, 255));
 | 
			
		||||
		lblTime.setBounds(180, 273, 72, 14);
 | 
			
		||||
		frame.getContentPane().add(lblTime);
 | 
			
		||||
		
 | 
			
		||||
		lblStatus = new JLabel("Status:");
 | 
			
		||||
		lblStatus.setForeground(new Color(255, 255, 255));
 | 
			
		||||
		lblStatus.setFont(new Font("Rockwell", Font.PLAIN, 16));
 | 
			
		||||
		lblStatus.setBounds(180, 317, 72, 18);
 | 
			
		||||
		frame.getContentPane().add(lblStatus);
 | 
			
		||||
 | 
			
		||||
		lblDate = new JLabel(currenttimeManager.toString());
 | 
			
		||||
		lblDate.setFont(new Font("Rockwell", Font.PLAIN, 16));
 | 
			
		||||
		lblDate.setForeground(Color.WHITE);
 | 
			
		||||
		lblDate.setBounds(235, 270, 326, 21);
 | 
			
		||||
		frame.getContentPane().add(lblDate);
 | 
			
		||||
		
 | 
			
		||||
		lblDestination = new JLabel();
 | 
			
		||||
		lblDestination.setForeground(Color.WHITE);
 | 
			
		||||
		lblDestination.setFont(new Font("Rockwell", Font.PLAIN, 16));
 | 
			
		||||
		lblDestination.setBounds(235, 317, 184, 18);
 | 
			
		||||
		frame.getContentPane().add(lblDestination);
 | 
			
		||||
		Calendar cal = new GregorianCalendar();
 | 
			
		||||
		cal.setTime(currenttimeManager);
 | 
			
		||||
    	if (cal.get(Calendar.DAY_OF_MONTH) == 9)
 | 
			
		||||
			 lblDestination.setText("Heading to Arafat");
 | 
			
		||||
		else lblDestination.setText("Heading to Hotels");
 | 
			
		||||
    	
 | 
			
		||||
    	lblDistrict = new JLabel("District: ");
 | 
			
		||||
		lblDistrict.setForeground(Color.WHITE);
 | 
			
		||||
		lblDistrict.setFont(new Font("Rockwell", Font.PLAIN, 16));
 | 
			
		||||
		lblDistrict.setBackground(Color.LIGHT_GRAY);
 | 
			
		||||
		lblDistrict.setBounds(180, 370, 72, 14);
 | 
			
		||||
		frame.getContentPane().add(lblDistrict);
 | 
			
		||||
		
 | 
			
		||||
		lblDistrictValue = new JLabel();
 | 
			
		||||
		lblDistrictValue.setForeground(Color.WHITE);
 | 
			
		||||
		lblDistrictValue.setFont(new Font("Rockwell", Font.PLAIN, 16));
 | 
			
		||||
		lblDistrictValue.setBackground(Color.BLACK);
 | 
			
		||||
		lblDistrictValue.setBounds(247, 371, 129, 12);
 | 
			
		||||
		frame.getContentPane().add(lblDistrictValue);
 | 
			
		||||
		
 | 
			
		||||
		textPane = new JTextPane();
 | 
			
		||||
		textPane.setFont(new Font("Rockwell", Font.PLAIN, 16));
 | 
			
		||||
		textPane.setForeground(Color.WHITE);
 | 
			
		||||
		textPane.setBackground(Color.BLACK);
 | 
			
		||||
		
 | 
			
		||||
		JScrollPane scrolltext = new JScrollPane(textPane);
 | 
			
		||||
		scrolltext.setBounds(523, 271, 384, 133);
 | 
			
		||||
		frame.getContentPane().add(scrolltext);
 | 
			
		||||
 | 
			
		||||
		
 | 
			
		||||
		frame.setVisible(true);
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	
 | 
			
		||||
	public void updateTable() {
 | 
			
		||||
		busData = new Object[vehicles.size()][6];
 | 
			
		||||
		for (int i = 0; i < vehicles.size(); i++) {
 | 
			
		||||
			busData[i][0] = vehicles.get(i).getUID();
 | 
			
		||||
			if (vehicles.get(i).isMoving())
 | 
			
		||||
				busData[i][1] = vehicles.get(i).getCurrentStreet().getName();
 | 
			
		||||
			else busData[i][1] = "Not Moving";
 | 
			
		||||
			busData[i][2] = vehicles.get(i).getCurrentLocation();
 | 
			
		||||
			if (vehicles.get(i).getProgress() != null)
 | 
			
		||||
				busData[i][3] = vehicles.get(i).getProgress();
 | 
			
		||||
			else busData[i][3] = "%0";
 | 
			
		||||
			busData[i][4] = vehicles.get(i).getTripTime();
 | 
			
		||||
			if (vehicles.get(i).isArrivedToDest())
 | 
			
		||||
				busData[i][5] = getShortTime(vehicles.get(i).getTimeOfArrival());
 | 
			
		||||
			else busData[i][5] = "NOT Arrived";
 | 
			
		||||
		}
 | 
			
		||||
		table.setModel(new DefaultTableModel(busData ,busColNames));
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	
 | 
			
		||||
	public void updateVehicles(ArrayList<Vehicle> vehiclesDistrict) {
 | 
			
		||||
		vehicles.clear();
 | 
			
		||||
		vehicles.addAll(vehiclesDistrict);
 | 
			
		||||
		lblDistrictValue.setText(((Bus)vehiclesDistrict.get(0)).getCampaign().getHotelDistrict().name());
 | 
			
		||||
		lblDate.setText(currenttimeManager.toString());
 | 
			
		||||
		updateTable();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private String getShortTime(Date time) {
 | 
			
		||||
		Calendar cal = new GregorianCalendar();
 | 
			
		||||
		cal.setTime(time);
 | 
			
		||||
		return String.format("%02d:%02d", cal.get(Calendar.HOUR), cal.get(Calendar.MINUTE));
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
@ -1,127 +0,0 @@
 | 
			
		||||
import java.awt.Color;
 | 
			
		||||
import java.awt.Font;
 | 
			
		||||
import java.util.Date;
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
 | 
			
		||||
import javax.swing.JFrame;
 | 
			
		||||
import javax.swing.JLabel;
 | 
			
		||||
import javax.swing.JScrollPane;
 | 
			
		||||
import javax.swing.JTable;
 | 
			
		||||
import javax.swing.ListSelectionModel;
 | 
			
		||||
import javax.swing.event.ListSelectionListener;
 | 
			
		||||
import javax.swing.table.DefaultTableModel;
 | 
			
		||||
import javax.swing.JComboBox;
 | 
			
		||||
import javax.swing.DefaultComboBoxModel;
 | 
			
		||||
import javax.swing.JTextField;
 | 
			
		||||
import javax.swing.JScrollBar;
 | 
			
		||||
 | 
			
		||||
public class GUI_ViewRoute {
 | 
			
		||||
	JFrame frame;
 | 
			
		||||
	private String[] routeColNames = {"Num", "Status", "Length","Capacity", "Best Time", "Used By"};
 | 
			
		||||
	private Object[][] routeData;
 | 
			
		||||
	private JTable table;
 | 
			
		||||
	private Route[] stdRoute;
 | 
			
		||||
	private Date currenttimeManager;
 | 
			
		||||
	private ArrayList<Campaign> listOfCampaigns;
 | 
			
		||||
	private JTextField txtStreets;
 | 
			
		||||
	private JLabel lblDate;
 | 
			
		||||
	private JLabel lblTime;
 | 
			
		||||
	
 | 
			
		||||
	public GUI_ViewRoute(Route[] stdRoute, ArrayList<Campaign> listOfCampaigns, Date currenttimeManager) {
 | 
			
		||||
		this.stdRoute = stdRoute;
 | 
			
		||||
		this.listOfCampaigns = listOfCampaigns;
 | 
			
		||||
		this.currenttimeManager = currenttimeManager;
 | 
			
		||||
		makeFrame();	
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
	private void makeFrame() {
 | 
			
		||||
		frame = new JFrame("Routes");
 | 
			
		||||
		frame.getContentPane().setBackground(new Color(50,50,50));
 | 
			
		||||
		frame.getContentPane().setForeground(new Color(0, 0, 0));
 | 
			
		||||
		frame.setBounds(100,100,815,480);
 | 
			
		||||
		frame.getContentPane().setLayout(null);
 | 
			
		||||
		frame.setLocationRelativeTo(null);
 | 
			
		||||
		
 | 
			
		||||
		routeData = new Object[stdRoute.length][6];
 | 
			
		||||
		for (int i = 0; i < stdRoute.length; i++) {
 | 
			
		||||
			routeData[i][0] = i;
 | 
			
		||||
			routeData[i][1] = String.format("%s : %s",stdRoute[i].getHotelArea(),stdRoute[i].getMashier());
 | 
			
		||||
			routeData[i][2] = stdRoute[i].getTotalLength();
 | 
			
		||||
			routeData[i][3] = String.format("%.2f",stdRoute[i].capcity());
 | 
			
		||||
			routeData[i][4] = stdRoute[i].getFastestTimeOfTravel(new Bus());
 | 
			
		||||
			int count = 0;
 | 
			
		||||
			for (Campaign campaign : listOfCampaigns)
 | 
			
		||||
				if (campaign.getRoute() == stdRoute[i])
 | 
			
		||||
					count += campaign.getVehicles().size();
 | 
			
		||||
			
 | 
			
		||||
			routeData[i][5] = String.format("%d buses", count);
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		
 | 
			
		||||
		table = new JTable(routeData,routeColNames);
 | 
			
		||||
		table.setModel(new DefaultTableModel(routeData,routeColNames));
 | 
			
		||||
		table.getColumnModel().getColumn(0).setPreferredWidth(30);
 | 
			
		||||
		table.getColumnModel().getColumn(1).setPreferredWidth(190);
 | 
			
		||||
		table.getColumnModel().getColumn(2).setPreferredWidth(55);
 | 
			
		||||
		table.getColumnModel().getColumn(3).setPreferredWidth(57);
 | 
			
		||||
		table.getColumnModel().getColumn(5).setPreferredWidth(75);
 | 
			
		||||
		table.setColumnSelectionAllowed(true);
 | 
			
		||||
		table.setCellSelectionEnabled(true);
 | 
			
		||||
		DefaultTableModel model = new DefaultTableModel();
 | 
			
		||||
		model.setColumnIdentifiers(routeColNames);
 | 
			
		||||
		ListSelectionModel model2 = table.getSelectionModel();
 | 
			
		||||
		model2.addListSelectionListener(e -> {
 | 
			
		||||
			int row = model2.getMinSelectionIndex();
 | 
			
		||||
			String streets = "";
 | 
			
		||||
			for (Street street : stdRoute[row].getStreets())
 | 
			
		||||
				streets += street.getName().name() +" >>  ";
 | 
			
		||||
			if (stdRoute[row].getMashier() == Mashier.ARAFAT)
 | 
			
		||||
				txtStreets.setText(stdRoute[row].getHotelArea().name()+" >>  "+streets+stdRoute[row].getMashier().name());
 | 
			
		||||
			else txtStreets.setText(stdRoute[row].getMashier().name()+" >>  "+streets+stdRoute[row].getHotelArea().name());
 | 
			
		||||
		});
 | 
			
		||||
		table.getTableHeader().setBackground(new Color(17,17,17));
 | 
			
		||||
		table.getTableHeader().setFont(new Font("Rockwell", Font.PLAIN, 18));
 | 
			
		||||
		table.getTableHeader().setForeground(Color.WHITE);
 | 
			
		||||
		table.setBackground(new Color(17,17,17));
 | 
			
		||||
		table.setForeground(Color.WHITE);
 | 
			
		||||
		table.setGridColor(new Color(102, 102, 102));
 | 
			
		||||
		table.setFont(new Font("Rockwell", Font.PLAIN, 18));
 | 
			
		||||
		table.setRowHeight(25);
 | 
			
		||||
		table.setAutoCreateRowSorter(true);
 | 
			
		||||
		table.revalidate();
 | 
			
		||||
		
 | 
			
		||||
		
 | 
			
		||||
		JScrollPane scrollPane = new JScrollPane(table);
 | 
			
		||||
		scrollPane.setBounds(10, 44, 755, 300);
 | 
			
		||||
		frame.getContentPane().add(scrollPane);
 | 
			
		||||
		
 | 
			
		||||
		txtStreets = new JTextField("Select Route");
 | 
			
		||||
		txtStreets.setBackground(Color.BLACK);
 | 
			
		||||
		txtStreets.setForeground(Color.WHITE);
 | 
			
		||||
		txtStreets.setFont(new Font("Rockwell", Font.PLAIN, 17));
 | 
			
		||||
		txtStreets.setBounds(10, 382, 755, 48);
 | 
			
		||||
		frame.getContentPane().add(txtStreets);
 | 
			
		||||
		txtStreets.setColumns(10);
 | 
			
		||||
		
 | 
			
		||||
		lblTime = new JLabel("Time:");
 | 
			
		||||
		lblTime.setForeground(Color.WHITE);
 | 
			
		||||
		lblTime.setFont(new Font("Rockwell", Font.PLAIN, 16));
 | 
			
		||||
		lblTime.setBounds(10, 11, 72, 20);
 | 
			
		||||
		frame.getContentPane().add(lblTime);
 | 
			
		||||
		
 | 
			
		||||
		lblDate = new JLabel(currenttimeManager.toString());
 | 
			
		||||
		lblDate.setForeground(Color.WHITE);
 | 
			
		||||
		lblDate.setFont(new Font("Rockwell", Font.PLAIN, 16));
 | 
			
		||||
		lblDate.setBounds(61, 11, 326, 20);
 | 
			
		||||
		frame.getContentPane().add(lblDate);
 | 
			
		||||
		
 | 
			
		||||
		JLabel lblStreets = new JLabel("Streets :");
 | 
			
		||||
		lblStreets.setForeground(Color.WHITE);
 | 
			
		||||
		lblStreets.setFont(new Font("Rockwell", Font.PLAIN, 16));
 | 
			
		||||
		lblStreets.setBounds(10, 355, 72, 20);
 | 
			
		||||
		frame.getContentPane().add(lblStreets);
 | 
			
		||||
		
 | 
			
		||||
		frame.setVisible(true);
 | 
			
		||||
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
@ -1,272 +0,0 @@
 | 
			
		||||
import java.awt.Color;
 | 
			
		||||
import java.awt.Font;
 | 
			
		||||
import java.util.Calendar;
 | 
			
		||||
import java.util.Date;
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.GregorianCalendar;
 | 
			
		||||
import javax.swing.JFrame;
 | 
			
		||||
import javax.swing.JScrollPane;
 | 
			
		||||
import javax.swing.JTable;
 | 
			
		||||
import javax.swing.event.ListSelectionEvent;
 | 
			
		||||
import javax.swing.event.ListSelectionListener;
 | 
			
		||||
import javax.swing.table.DefaultTableModel;
 | 
			
		||||
 | 
			
		||||
import javax.swing.JList;
 | 
			
		||||
import javax.swing.AbstractListModel;
 | 
			
		||||
import javax.swing.JTextField;
 | 
			
		||||
import javax.swing.JLabel;
 | 
			
		||||
 | 
			
		||||
public class GUI_ViewStreet {
 | 
			
		||||
	private JFrame frame;
 | 
			
		||||
	private Street street;
 | 
			
		||||
	private ArrayList<Vehicle> vehicles = new ArrayList<>();
 | 
			
		||||
	private Street[] stdStreet = new Street[StreetNames.values().length];
 | 
			
		||||
	private Date currenttimeManager;
 | 
			
		||||
	private Object[][] vehicleData;
 | 
			
		||||
	private String[] vehicleColNames = {"ID", "District", "location","Progress", "trip time"};
 | 
			
		||||
	private JTable table;
 | 
			
		||||
	private JLabel lblCapcityValue; 
 | 
			
		||||
	private JLabel lblDate;
 | 
			
		||||
	private JLabel lblLanesValue;
 | 
			
		||||
	private JLabel lblNumVehicles;
 | 
			
		||||
	private JLabel lblLengthValue;
 | 
			
		||||
	private JTextField txtLow;
 | 
			
		||||
	private JTextField[] textFieldArray = new JTextField[20];
 | 
			
		||||
	private JTextField txtHigh;
 | 
			
		||||
	
 | 
			
		||||
	public GUI_ViewStreet(Street[] streets, Date currenttimeManager) {
 | 
			
		||||
		stdStreet = streets.clone();
 | 
			
		||||
		this.currenttimeManager = (Date) currenttimeManager.clone();
 | 
			
		||||
		makeFrame();
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	private void makeFrame() {
 | 
			
		||||
		//street = stdStreet[0];
 | 
			
		||||
		frame = new JFrame("Streets");
 | 
			
		||||
		frame.getContentPane().setBackground(new Color(50,50,50));
 | 
			
		||||
		frame.getContentPane().setForeground(new Color(0, 0, 0));
 | 
			
		||||
		frame.setBounds(100,100,815,480);
 | 
			
		||||
		frame.getContentPane().setLayout(null);
 | 
			
		||||
		frame.setLocationRelativeTo(null);
 | 
			
		||||
		
 | 
			
		||||
		vehicleData = new Object[vehicles.size()][6];
 | 
			
		||||
		for (int i = 0; i < vehicles.size(); i++) {
 | 
			
		||||
			vehicleData[i][0] = vehicles.get(i).getUID();
 | 
			
		||||
			if (vehicles.get(i) instanceof Bus)
 | 
			
		||||
				vehicleData[i][1] = ((Bus)vehicles.get(i)).getCampaign().getHotelDistrict().name();
 | 
			
		||||
			else vehicleData[i][1] = "Local Vehicle";
 | 
			
		||||
			vehicleData[i][2] = vehicles.get(i).getCurrentLocation();
 | 
			
		||||
			vehicleData[i][3] = vehicles.get(i).getProgress();
 | 
			
		||||
			vehicleData[i][4] = vehicles.get(i).getTripTime();
 | 
			
		||||
			
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		table = new JTable(vehicleData,vehicleColNames);
 | 
			
		||||
		table.setColumnSelectionAllowed(true);
 | 
			
		||||
		table.setCellSelectionEnabled(true);
 | 
			
		||||
		DefaultTableModel model = new DefaultTableModel();
 | 
			
		||||
		model.setColumnIdentifiers(vehicleColNames);
 | 
			
		||||
		table.getTableHeader().setBackground(new Color(17,17,17));
 | 
			
		||||
		table.getTableHeader().setFont(new Font("Rockwell", Font.PLAIN, 18));
 | 
			
		||||
		table.getTableHeader().setForeground(Color.WHITE);
 | 
			
		||||
		table.setModel(new DefaultTableModel(vehicleData ,vehicleColNames));
 | 
			
		||||
		table.setBackground(new Color(17,17,17));
 | 
			
		||||
		table.setForeground(Color.WHITE);
 | 
			
		||||
		table.setGridColor(new Color(102, 102, 102));
 | 
			
		||||
		table.setFont(new Font("Rockwell", Font.PLAIN, 18));
 | 
			
		||||
		table.setRowHeight(25);
 | 
			
		||||
		table.setAutoCreateRowSorter(true);
 | 
			
		||||
		table.revalidate();
 | 
			
		||||
		
 | 
			
		||||
		JScrollPane scrollPane = new JScrollPane(table);
 | 
			
		||||
		scrollPane.setBounds(10, 194, 755, 236);
 | 
			
		||||
		frame.getContentPane().add(scrollPane);
 | 
			
		||||
		
 | 
			
		||||
		JList list = new JList();
 | 
			
		||||
		list.setFont(new Font("Tahoma", Font.PLAIN, 14));
 | 
			
		||||
		list.setBackground(Color.GRAY);
 | 
			
		||||
		list.setModel(new AbstractListModel() {
 | 
			
		||||
			Street[] streets = stdStreet;
 | 
			
		||||
			public int getSize() {
 | 
			
		||||
				return stdStreet.length;
 | 
			
		||||
			}
 | 
			
		||||
			public Object getElementAt(int index) {
 | 
			
		||||
				return streets[index].getName().name();
 | 
			
		||||
			}
 | 
			
		||||
		});
 | 
			
		||||
		list.addListSelectionListener(
 | 
			
		||||
				new ListSelectionListener() {
 | 
			
		||||
					public void valueChanged(ListSelectionEvent e) {
 | 
			
		||||
						street = stdStreet[list.getSelectedIndex()];
 | 
			
		||||
						vehicles = street.getVehicles();
 | 
			
		||||
						updateTable();
 | 
			
		||||
						for (int i = 0; i < textFieldArray.length; i++) {
 | 
			
		||||
							int colorFactor = (int)((1-capcityPoint(i))*255); 
 | 
			
		||||
							textFieldArray[i].setBackground(new Color(255,colorFactor,0));
 | 
			
		||||
						}
 | 
			
		||||
						lblCapcityValue.setText(String.format("%%%d", street.getPercentRemainingCapacity()));
 | 
			
		||||
						lblDate.setText(currenttimeManager.toString());
 | 
			
		||||
						lblNumVehicles.setText(String.format("%d", street.getVehicles().size()));
 | 
			
		||||
						lblLengthValue.setText(String.format("%.2f", street.getLength()));
 | 
			
		||||
						lblLanesValue.setText(String.format("%d", street.getNumberOfLanes()));
 | 
			
		||||
					}
 | 
			
		||||
				});
 | 
			
		||||
		list.setBounds(10, 11, 118, 146);
 | 
			
		||||
		JScrollPane scrollList = new JScrollPane(list);
 | 
			
		||||
		scrollList.setBounds(10, 11, 173, 172);
 | 
			
		||||
		frame.getContentPane().add(scrollList);
 | 
			
		||||
		
 | 
			
		||||
		txtLow = new JTextField("Low");
 | 
			
		||||
		txtLow.setFont(new Font("Rockwell", Font.BOLD, 13));
 | 
			
		||||
		txtLow.setDisabledTextColor(Color.BLACK);
 | 
			
		||||
		txtLow.setEnabled(false);
 | 
			
		||||
		txtLow.setEditable(false);
 | 
			
		||||
		txtLow.setBackground(Color.YELLOW);
 | 
			
		||||
		txtLow.setBounds(710, 105, 40, 20);
 | 
			
		||||
		frame.getContentPane().add(txtLow);
 | 
			
		||||
		
 | 
			
		||||
		txtHigh = new JTextField("High");
 | 
			
		||||
		txtHigh.setFont(new Font("Rockwell", Font.BOLD, 13));
 | 
			
		||||
		txtHigh.setDisabledTextColor(Color.BLACK);
 | 
			
		||||
		txtHigh.setEnabled(false);
 | 
			
		||||
		txtHigh.setEditable(false);
 | 
			
		||||
		txtHigh.setColumns(0);
 | 
			
		||||
		txtHigh.setBackground(Color.RED);
 | 
			
		||||
		txtHigh.setBounds(710, 80, 40, 20);
 | 
			
		||||
		frame.getContentPane().add(txtHigh);
 | 
			
		||||
		
 | 
			
		||||
		JLabel lblTime = new JLabel("Time:");
 | 
			
		||||
		lblTime.setForeground(Color.WHITE);
 | 
			
		||||
		lblTime.setFont(new Font("Rockwell", Font.PLAIN, 16));
 | 
			
		||||
		lblTime.setBounds(193, 11, 72, 20);
 | 
			
		||||
		frame.getContentPane().add(lblTime);
 | 
			
		||||
		
 | 
			
		||||
		lblDate = new JLabel(currenttimeManager.toString());
 | 
			
		||||
		lblDate.setForeground(Color.WHITE);
 | 
			
		||||
		lblDate.setFont(new Font("Rockwell", Font.PLAIN, 16));
 | 
			
		||||
		lblDate.setBounds(243, 11, 326, 20);
 | 
			
		||||
		frame.getContentPane().add(lblDate);
 | 
			
		||||
		
 | 
			
		||||
		JLabel lblStatus = new JLabel("Status:");
 | 
			
		||||
		lblStatus.setForeground(Color.WHITE);
 | 
			
		||||
		lblStatus.setFont(new Font("Rockwell", Font.PLAIN, 16));
 | 
			
		||||
		lblStatus.setBounds(511, 11, 72, 20);
 | 
			
		||||
		frame.getContentPane().add(lblStatus);
 | 
			
		||||
		
 | 
			
		||||
		JLabel lblDestination = new JLabel();
 | 
			
		||||
		lblDestination.setForeground(Color.WHITE);
 | 
			
		||||
		lblDestination.setFont(new Font("Rockwell", Font.PLAIN, 16));
 | 
			
		||||
		lblDestination.setBounds(568, 11, 184, 20);
 | 
			
		||||
		Calendar cal = new GregorianCalendar();
 | 
			
		||||
		cal.setTime(currenttimeManager);
 | 
			
		||||
		if (cal.get(Calendar.DAY_OF_MONTH) == 9)
 | 
			
		||||
			 lblDestination.setText("Heading to Arafat");
 | 
			
		||||
		else lblDestination.setText("Heading to Hotels");
 | 
			
		||||
		frame.getContentPane().add(lblDestination);
 | 
			
		||||
		
 | 
			
		||||
		JLabel lblCapcity = new JLabel("Capcity:");
 | 
			
		||||
		lblCapcity.setForeground(Color.WHITE);
 | 
			
		||||
		lblCapcity.setFont(new Font("Rockwell", Font.PLAIN, 16));
 | 
			
		||||
		lblCapcity.setBounds(193, 45, 72, 20);
 | 
			
		||||
		frame.getContentPane().add(lblCapcity);
 | 
			
		||||
		
 | 
			
		||||
		lblCapcityValue = new JLabel();
 | 
			
		||||
		lblCapcityValue.setForeground(Color.WHITE);
 | 
			
		||||
		lblCapcityValue.setFont(new Font("Rockwell", Font.PLAIN, 16));
 | 
			
		||||
		lblCapcityValue.setBounds(258, 45, 48, 20);
 | 
			
		||||
		frame.getContentPane().add(lblCapcityValue);
 | 
			
		||||
		
 | 
			
		||||
		JLabel lblVehicles = new JLabel("Vehicles: ");
 | 
			
		||||
		lblVehicles.setForeground(Color.WHITE);
 | 
			
		||||
		lblVehicles.setFont(new Font("Rockwell", Font.PLAIN, 16));
 | 
			
		||||
		lblVehicles.setBounds(370, 45, 72, 20);
 | 
			
		||||
		frame.getContentPane().add(lblVehicles);
 | 
			
		||||
		
 | 
			
		||||
		lblNumVehicles = new JLabel();
 | 
			
		||||
		lblNumVehicles.setForeground(Color.WHITE);
 | 
			
		||||
		lblNumVehicles.setFont(new Font("Rockwell", Font.PLAIN, 16));
 | 
			
		||||
		lblNumVehicles.setBounds(441, 45, 61, 20);
 | 
			
		||||
		frame.getContentPane().add(lblNumVehicles);
 | 
			
		||||
		
 | 
			
		||||
		JLabel lblLength = new JLabel("Length:");
 | 
			
		||||
		lblLength.setForeground(Color.WHITE);
 | 
			
		||||
		lblLength.setFont(new Font("Rockwell", Font.PLAIN, 16));
 | 
			
		||||
		lblLength.setBounds(193, 85, 61, 20);
 | 
			
		||||
		frame.getContentPane().add(lblLength);
 | 
			
		||||
		
 | 
			
		||||
		lblLengthValue = new JLabel();
 | 
			
		||||
		lblLengthValue.setForeground(Color.WHITE);
 | 
			
		||||
		lblLengthValue.setFont(new Font("Rockwell", Font.PLAIN, 16));
 | 
			
		||||
		lblLengthValue.setBounds(253, 85, 93, 20);
 | 
			
		||||
		frame.getContentPane().add(lblLengthValue);
 | 
			
		||||
		
 | 
			
		||||
		JLabel lblLanes = new JLabel("Lanes");
 | 
			
		||||
		lblLanes.setForeground(Color.WHITE);
 | 
			
		||||
		lblLanes.setFont(new Font("Rockwell", Font.PLAIN, 16));
 | 
			
		||||
		lblLanes.setBounds(370, 85, 61, 20);
 | 
			
		||||
		frame.getContentPane().add(lblLanes);
 | 
			
		||||
		
 | 
			
		||||
		lblLanesValue = new JLabel();
 | 
			
		||||
		lblLanesValue.setForeground(Color.WHITE);
 | 
			
		||||
		lblLanesValue.setFont(new Font("Rockwell", Font.PLAIN, 16));
 | 
			
		||||
		lblLanesValue.setBounds(431, 85, 26, 20);
 | 
			
		||||
		frame.getContentPane().add(lblLanesValue);
 | 
			
		||||
		
 | 
			
		||||
		JLabel lbl100 = new JLabel();
 | 
			
		||||
		lbl100.setText("%100");
 | 
			
		||||
		lbl100.setForeground(Color.WHITE);
 | 
			
		||||
		lbl100.setFont(new Font("Rockwell", Font.PLAIN, 16));
 | 
			
		||||
		lbl100.setBounds(715, 170, 45, 15);
 | 
			
		||||
		frame.getContentPane().add(lbl100);
 | 
			
		||||
		
 | 
			
		||||
		JLabel lbl0 = new JLabel();
 | 
			
		||||
		lbl0.setText("%0");
 | 
			
		||||
		lbl0.setForeground(Color.WHITE);
 | 
			
		||||
		lbl0.setFont(new Font("Rockwell", Font.PLAIN, 16));
 | 
			
		||||
		lbl0.setBounds(193, 170, 25, 15);
 | 
			
		||||
		frame.getContentPane().add(lbl0);
 | 
			
		||||
		
 | 
			
		||||
		JLabel lblCapcityPoint = new JLabel("CapcityPoint:");
 | 
			
		||||
		lblCapcityPoint.setForeground(Color.WHITE);
 | 
			
		||||
		lblCapcityPoint.setFont(new Font("Rockwell", Font.PLAIN, 16));
 | 
			
		||||
		lblCapcityPoint.setBounds(193, 120, 101, 20);
 | 
			
		||||
		frame.getContentPane().add(lblCapcityPoint);
 | 
			
		||||
		
 | 
			
		||||
		
 | 
			
		||||
		for (int i = 0; i < textFieldArray.length; i++) {
 | 
			
		||||
			textFieldArray[i] = new JTextField();
 | 
			
		||||
			textFieldArray[i].setEnabled(false);
 | 
			
		||||
			textFieldArray[i].setEditable(false);
 | 
			
		||||
			textFieldArray[i].setBackground(new Color(70, 70, 70));
 | 
			
		||||
			textFieldArray[i].setBounds(190+i*28, 142, 28, 20);
 | 
			
		||||
			frame.getContentPane().add(textFieldArray[i]);
 | 
			
		||||
			textFieldArray[i].setColumns(0);
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		frame.setVisible(true);
 | 
			
		||||
		
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public void updateTable() {
 | 
			
		||||
		if (vehicles.isEmpty()) return;
 | 
			
		||||
		vehicleData = new Object[vehicles.size()][6];
 | 
			
		||||
		for (int i = 0; i < vehicles.size(); i++) {
 | 
			
		||||
			vehicleData[i][0] = vehicles.get(i).getUID();// TODO: There is an Exception error here;
 | 
			
		||||
			if (vehicles.get(i) instanceof Bus)
 | 
			
		||||
				vehicleData[i][1] = ((Bus)vehicles.get(i)).getCampaign().getHotelDistrict().name();
 | 
			
		||||
			else vehicleData[i][1] = "Local Vehicle";
 | 
			
		||||
			vehicleData[i][2] = vehicles.get(i).getCurrentLocation();
 | 
			
		||||
			vehicleData[i][3] = vehicles.get(i).getProgress();
 | 
			
		||||
			vehicleData[i][4] = vehicles.get(i).getTripTime();
 | 
			
		||||
			
 | 
			
		||||
		}
 | 
			
		||||
		table.setModel(new DefaultTableModel(vehicleData ,vehicleColNames));
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public double capcityPoint(int x) {
 | 
			
		||||
		double part = street.getLength()/20;
 | 
			
		||||
		double capcity = street.capcityPoint(x*part, (x+1)*part);
 | 
			
		||||
		
 | 
			
		||||
		return capcity;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
@ -1,18 +0,0 @@
 | 
			
		||||
import java.util.Date;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Class to be used in Hajj-sim. Overrides toString()
 | 
			
		||||
 * Incomplete.
 | 
			
		||||
 */
 | 
			
		||||
class HijriDate extends Date {
 | 
			
		||||
 | 
			
		||||
    public HijriDate(long timeInMillis) {
 | 
			
		||||
        super(timeInMillis);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public String toString(){
 | 
			
		||||
        return super.toString().replaceAll("Jan","Dhu'l-Hijja")
 | 
			
		||||
                .replaceAll("AST", "");
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@ -1,46 +0,0 @@
 | 
			
		||||
import java.util.Scanner;
 | 
			
		||||
 | 
			
		||||
public class InputListener implements Runnable {
 | 
			
		||||
 | 
			
		||||
    private volatile String input = "";
 | 
			
		||||
    private volatile boolean hasNew;
 | 
			
		||||
    private volatile boolean pause;
 | 
			
		||||
    private final Scanner in;
 | 
			
		||||
    private boolean stop;
 | 
			
		||||
 | 
			
		||||
    public InputListener() {
 | 
			
		||||
        in = new Scanner(System.in);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void run() {
 | 
			
		||||
        while(!stop) {
 | 
			
		||||
            if (!pause){
 | 
			
		||||
                input = in.next();
 | 
			
		||||
                hasNew = true;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        System.out.println("Stopped input listener");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void stop() {
 | 
			
		||||
        stop = true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public String getInput() {
 | 
			
		||||
        hasNew = false;
 | 
			
		||||
        return input;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean hasNew() {
 | 
			
		||||
        return hasNew;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void pause() {
 | 
			
		||||
        pause = true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void unpause() {
 | 
			
		||||
        pause = false;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										1028
									
								
								src/MakkahCity.java
									
									
									
									
									
								
							
							
						
						
									
										1028
									
								
								src/MakkahCity.java
									
									
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							@ -35,15 +35,15 @@ public class PDate extends Calendar {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Date getStartTime() {
 | 
			
		||||
        return new HijriDate(startCalendar.getTimeInMillis());
 | 
			
		||||
        return startCalendar.getTime();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Date getEndTime(){
 | 
			
		||||
        return new HijriDate(endCalendar.getTimeInMillis());
 | 
			
		||||
        return endCalendar.getTime();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Date getCurrentTime() {
 | 
			
		||||
        return new HijriDate(currentCalendar.getTimeInMillis());
 | 
			
		||||
        return currentCalendar.getTime();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void step(int key, int value){
 | 
			
		||||
 | 
			
		||||
@ -1,6 +1,4 @@
 | 
			
		||||
import java.io.Serializable;
 | 
			
		||||
 | 
			
		||||
public class Route implements Travelable, Serializable {
 | 
			
		||||
public class Route {
 | 
			
		||||
 | 
			
		||||
    private Street[] streets;
 | 
			
		||||
    private District hotelArea;
 | 
			
		||||
@ -40,27 +38,10 @@ public class Route implements Travelable, Serializable {
 | 
			
		||||
        double totalLength = getTotalLength();
 | 
			
		||||
        int maxSpeed = vehicle.getMaxSpeed();
 | 
			
		||||
        int totalTime = (int) (totalLength/maxSpeed);
 | 
			
		||||
        String result = String.format("%02d:%02d",totalTime / 60, totalTime % 60);
 | 
			
		||||
        String result = String.format("%2d:%2d",totalTime % 60, totalTime /60);
 | 
			
		||||
        return result;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public String toString() {
 | 
			
		||||
        StringBuilder s = new StringBuilder();
 | 
			
		||||
        s.append(super.toString())
 | 
			
		||||
                .append("\n").append(String.format("%s:%s",getHotelArea(),getMashier()))
 | 
			
		||||
                .append("\n")
 | 
			
		||||
                .append("Length: ").append(getTotalLength())
 | 
			
		||||
                .append("\n")
 | 
			
		||||
                .append("Capacity: ").append(String.format("%.2f", capcity()))
 | 
			
		||||
                .append("\n")
 | 
			
		||||
                .append("Streets: ");
 | 
			
		||||
        for (Street street : this.getStreets())
 | 
			
		||||
            s.append(street.getName().name()).append(" ");
 | 
			
		||||
        s.append("\nBest Time: ").append(getFastestTimeOfTravel(new Bus())).append("\n");
 | 
			
		||||
        return s.toString();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public District getHotelArea() {
 | 
			
		||||
        return hotelArea;
 | 
			
		||||
    }
 | 
			
		||||
@ -69,15 +50,6 @@ public class Route implements Travelable, Serializable {
 | 
			
		||||
        return mashier;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public double capcity() {
 | 
			
		||||
    	double capcity = 0;
 | 
			
		||||
		for (Street str : getStreets()) {
 | 
			
		||||
			capcity += str.getPercentRemainingCapacity();
 | 
			
		||||
		}
 | 
			
		||||
		double c = capcity/(getStreets().length);
 | 
			
		||||
		return c;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
    private void setStreets(Street[] streets) {
 | 
			
		||||
        if (streets != null) this.streets = streets;
 | 
			
		||||
        else throwIllegal();
 | 
			
		||||
 | 
			
		||||
@ -1,13 +1,10 @@
 | 
			
		||||
import java.io.Serializable;
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.Date;
 | 
			
		||||
import java.util.HashMap;
 | 
			
		||||
 | 
			
		||||
public class Street implements Travelable, Serializable {
 | 
			
		||||
public class Street {
 | 
			
		||||
 | 
			
		||||
    private double length;
 | 
			
		||||
    private int numberOfLanes;
 | 
			
		||||
    private ArrayList<Vehicle> vehicles; //Current
 | 
			
		||||
    private ArrayList<Vehicle> vehicles;
 | 
			
		||||
    private StreetNames name;
 | 
			
		||||
  
 | 
			
		||||
  
 | 
			
		||||
@ -60,18 +57,18 @@ public class Street implements Travelable, Serializable {
 | 
			
		||||
        for(int i=0;i<vehicles.size();i++) {
 | 
			
		||||
            totalLenthofCar+=vehicles.get(i).getVehicleSize();
 | 
			
		||||
        }
 | 
			
		||||
        int percent = 0;
 | 
			
		||||
        if (totalLenthofCar > totalLength){
 | 
			
		||||
            percent = (int) (totalLength/totalLenthofCar);
 | 
			
		||||
            percent *= 100;
 | 
			
		||||
            percent +=  totalLength - (totalLength % totalLenthofCar);
 | 
			
		||||
        }
 | 
			
		||||
        else {
 | 
			
		||||
            percent = (int)(totalLength - totalLenthofCar);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return percent;
 | 
			
		||||
        //return totalLength - totalLenthofCar;
 | 
			
		||||
//        int percent = 0;
 | 
			
		||||
//        if (totalLenthofCar > totalLength){
 | 
			
		||||
//            percent = (int) (totalLength/totalLenthofCar);
 | 
			
		||||
//            percent *= 100;
 | 
			
		||||
//            percent +=  totalLength - (totalLength % totalLenthofCar);
 | 
			
		||||
//        }
 | 
			
		||||
//        else {
 | 
			
		||||
//            percent = (int)(totalLength - totalLenthofCar);
 | 
			
		||||
//        }
 | 
			
		||||
//
 | 
			
		||||
//        return percent;
 | 
			
		||||
        return totalLength - totalLenthofCar;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public int getPercentRemainingCapacity() {
 | 
			
		||||
@ -86,7 +83,10 @@ public class Street implements Travelable, Serializable {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void addVehicle(Vehicle vehicle) {
 | 
			
		||||
        //if(capcity() > vehicle.getVehicleSize() + 0.5) {
 | 
			
		||||
            //adds incoming vehicle in last.
 | 
			
		||||
            vehicles.add(vehicle);
 | 
			
		||||
        //}
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public double capcityPoint(double min, double max) {
 | 
			
		||||
@ -136,6 +136,8 @@ public class Street implements Travelable, Serializable {
 | 
			
		||||
    		return 	(vehicle.getRoute().getStreets()[nextIndex]);
 | 
			
		||||
    			else
 | 
			
		||||
    				return null;
 | 
			
		||||
    	
 | 
			
		||||
    		
 | 
			
		||||
    	}
 | 
			
		||||
 | 
			
		||||
    public int getNumberOfBuses() {
 | 
			
		||||
@ -153,50 +155,4 @@ public class Street implements Travelable, Serializable {
 | 
			
		||||
        }
 | 
			
		||||
        return number;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public String toString(){
 | 
			
		||||
        StringBuilder printedStreet = new StringBuilder();
 | 
			
		||||
        //Imagine steert is 32 units in lengths (scale down)
 | 
			
		||||
        for (int i = 0; i < 32; i++){
 | 
			
		||||
            printedStreet.append("----");
 | 
			
		||||
        }
 | 
			
		||||
        printedStreet.append("\n");
 | 
			
		||||
        //This is vary bad. Should copy vehicles list and reduce when a vehicle is counted;
 | 
			
		||||
        for (int i = 0; i < 32; i++){
 | 
			
		||||
            int cars = 0;
 | 
			
		||||
            for (Vehicle vehicle : vehicles){
 | 
			
		||||
                double realLocation = vehicle.getCurrentLocation();
 | 
			
		||||
                int scaledLocation = (int)((realLocation*32) / this.length);
 | 
			
		||||
                if (scaledLocation == i) cars++;
 | 
			
		||||
            }
 | 
			
		||||
            //if 'cars' is 4 digits or more it will distort the output
 | 
			
		||||
            printedStreet.append(String.format("%03d ", cars));
 | 
			
		||||
        }
 | 
			
		||||
        printedStreet.append("\n");
 | 
			
		||||
        for (int i = 0; i < 32; i++){
 | 
			
		||||
            printedStreet.append("----");
 | 
			
		||||
        }
 | 
			
		||||
        return String.format("Street name: %s, Length: %.2f, Lanes: %d, Vehicles: %d, Capacity: %%%s\nDensity:\n%s\n",
 | 
			
		||||
                name.name(),
 | 
			
		||||
                length,
 | 
			
		||||
                numberOfLanes,
 | 
			
		||||
                vehicles.size(),
 | 
			
		||||
                getPercentRemainingCapacity(),
 | 
			
		||||
                printedStreet.toString());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean isContainsBuses() {
 | 
			
		||||
    	for (Vehicle vehicle : this.vehicles) {
 | 
			
		||||
    		if (vehicle instanceof Bus)
 | 
			
		||||
    			return true;
 | 
			
		||||
    	}
 | 
			
		||||
    	return false;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public String getFastestTimeOfTravel(Vehicle vehicle) {
 | 
			
		||||
        double totalLength = length;
 | 
			
		||||
        int maxSpeed = vehicle.getMaxSpeed();
 | 
			
		||||
        int totalTime = (int) (totalLength/maxSpeed);
 | 
			
		||||
        return String.format("%02d:%02d",totalTime / 60, totalTime % 60);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -28,9 +28,4 @@ public class TrafficPoliceCar extends Vehicle implements CanBeGovtCar, CanFixAcc
 | 
			
		||||
    public int getMaxSpeed() {
 | 
			
		||||
        return Sedan.MAX_FORWARD;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public String getUID() {
 | 
			
		||||
        return TPC_UID;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -1,3 +0,0 @@
 | 
			
		||||
public interface Travelable {
 | 
			
		||||
    String getFastestTimeOfTravel(Vehicle vehicle);
 | 
			
		||||
}
 | 
			
		||||
@ -1,8 +1,7 @@
 | 
			
		||||
import java.io.Serializable;
 | 
			
		||||
import java.util.Date;
 | 
			
		||||
import java.util.HashMap;
 | 
			
		||||
 | 
			
		||||
public abstract class Vehicle implements Serializable {
 | 
			
		||||
public abstract class Vehicle {
 | 
			
		||||
 | 
			
		||||
    private double vehicleSize;
 | 
			
		||||
    private Route route;
 | 
			
		||||
@ -14,14 +13,11 @@ public abstract class Vehicle implements Serializable {
 | 
			
		||||
    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<>();
 | 
			
		||||
 | 
			
		||||
    public abstract int getMaxSpeed();
 | 
			
		||||
    public abstract String getUID();
 | 
			
		||||
 | 
			
		||||
    public Vehicle(double vehicleSize){
 | 
			
		||||
        setVehicleSize(vehicleSize);
 | 
			
		||||
@ -41,68 +37,8 @@ public abstract class Vehicle implements Serializable {
 | 
			
		||||
        setTimeOfArrival(MakkahCity.getTimeMan().getCurrentTime());
 | 
			
		||||
        getCurrentStreet().getVehicles().remove(this);
 | 
			
		||||
        this.currentLocation = 0;
 | 
			
		||||
        maxArrived();
 | 
			
		||||
        minArrived();
 | 
			
		||||
        if (totalDistanceTraveled > route.getTotalLength()) totalDistanceTraveled = route.getTotalLength();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    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);
 | 
			
		||||
@ -116,9 +52,6 @@ public abstract class Vehicle implements Serializable {
 | 
			
		||||
        this.route = route;
 | 
			
		||||
        this.arrivedToDest = false;
 | 
			
		||||
        this.routeTimeHistory.clear();
 | 
			
		||||
        this.timeStartedOnCurrentStreet = null;
 | 
			
		||||
        this.timeStartedMoving = null;
 | 
			
		||||
        this.timeOfArrival = null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void setVehicleSize(double vehicleSize) {
 | 
			
		||||
@ -230,38 +163,10 @@ public abstract class Vehicle implements Serializable {
 | 
			
		||||
        return 0;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public String getProgress() {
 | 
			
		||||
        int p = (int)((totalDistanceTraveled/route.getTotalLength())*100);
 | 
			
		||||
        if (p > 100) p = 100;
 | 
			
		||||
        return String.format("%%%d", p);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public String getTripTime() {
 | 
			
		||||
        long minutes = 0;
 | 
			
		||||
        if (timeStartedMoving != null && timeOfArrival != null){
 | 
			
		||||
            minutes = (getTimeOfArrival().getTime() - getTimeStartedMoving().getTime())/60000;
 | 
			
		||||
 | 
			
		||||
        }
 | 
			
		||||
        else if (timeStartedMoving != null) { //compare to now
 | 
			
		||||
            minutes = (MakkahCity.getTimeMan().getCurrentTime().getTime() - getTimeStartedMoving().getTime())/60000;
 | 
			
		||||
        }
 | 
			
		||||
        return String.format("%d:%02d", minutes /60, minutes % 60);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean hasCrossedStreet(Street street) {
 | 
			
		||||
        return routeTimeHistory.containsKey(street);
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    public String toString() {
 | 
			
		||||
        Street st = this.currentStreet;
 | 
			
		||||
        String streetString = "null";
 | 
			
		||||
        if (st != null) streetString = st.getName().name();
 | 
			
		||||
        return String.format("\nRoute: %s\nStreet: %s, Location: %.1f, Distance covered: %.1f, Progress: %s\n" +
 | 
			
		||||
                        "Arrived: %s\nStarting time: %s\nArrive Time:   %s\nTrip time: %s\n",
 | 
			
		||||
                this.route, streetString,
 | 
			
		||||
                this.getCurrentLocation(), this.totalDistanceTraveled, getProgress(), this.isArrivedToDest(),
 | 
			
		||||
                this.getTimeStartedMoving(), this.getTimeOfArrival(), getTripTime());
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user