I'm trying to create a class which reads an ambulances.csv and patients.csv file, run for a set period and then output the updated information to ambulances-2.csv and patients-2.csv (both input and output files use the same data formats).
Each patient has an (x, y) location. The initial positions of the ambulances and patients are read in from the data files. Every second, the ambulances will update their status and position. The new status and position depends on the current status:
The hospital: this exists on the grid at location (50, 50) • The ambulance stations: there are three stations at different locations on the grid: o Greenfields – (10, 0) o Bluelane – (30, 80) o Redvill – (90, 20)
1st spec ‘At station’: check if there is a new patient to pick up, if so, assign the closest unassigned patient to the ambulance and change the status to ‘Responding’. Otherwise, do nothing.
2nd spec ‘Responding’: move the ambulance towards the assigned patient by four moves. If the ambulance reaches the patient, change the status to ‘At scene’.
I was thinking to maybe create an ArrayList<Ambulance> and ArrayList<Patient> to be able to reference it and use if statements and then print it out onto the console to get an idea? But I wasn''t sure how to reference the hospital and stations. Any ideas would be great ! my second question as well so any criticism on the style is happily accepted
Contents of files.
Ambulances.csv
id x.location y.location status patient
A1 10 0 At Station
A2 10 0 At Station
A4 30 80 At Station
A8 90 20 At Station
A16 90 20 At Station
A64 12 12 Responding 1
A32 50 50 At Destination
A128 30 76 Returning
Patient.csv
id x.location y.location status ambulance
1 17 19 Assigned A64
2 50 50 Completed
3 78 29 Pending
4 97 12 Pending
5 27 17 Pending
6 28 17 Pending
7 67 2 Pending
8 3 99 Pending
9 30 81 Pending
10 49 50 Pending
What I have tried:
reading a file and I displayed it on Jtable but i want to try display it on console first
try {
BufferedReader br = new BufferedReader(new FileReader(new File("ambulances.csv")));
ArrayList<String[]> elements = new ArrayList<String[]>();
String line = "";
while((line = br.readLine())!=null) {
String[] splitted = line.split(",");
elements.add(splitted);
}
br.close();
String[] columNames = new String[] {"ID", "Location", "Status", "Patient"};
final Object[][] content = new Object[elements.size()-1][5];
for(int i=1; i<elements.size(); i++) {
content[i-1][0] = elements.get(i)[0];
content[i-1][1] = "("+ elements.get(i)[1] + ", " + elements.get(i)[2] + ")";
content[i-1][2] = elements.get(i)[3].replace("\"", "");
if (elements.get(i).length == 5) {
content[i-1][3] = elements.get(i)[4].replace("\"", "");
}
else content[i-1][3] = "-";
}
table = new JTable();
table.setModel(new DefaultTableModel(content,columNames));
table.setVisible(true);