-
Notifications
You must be signed in to change notification settings - Fork 0
/
Print.java
executable file
·40 lines (35 loc) · 1.4 KB
/
Print.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/*
* This class will print out the results of the Elevator
*/
import java.util.ArrayList;
import java.io.PrintWriter;
import java.io.FileNotFoundException;
import java.io.UnsupportedEncodingException;
import java.sql.Time;
public class Print {
@SuppressWarnings("deprecation")
public static void print (ArrayList<PassengerReleased> released) {
try {
int previousFloor = 0;
PrintWriter writer = new PrintWriter("results.txt", "UTF-8");
writer.println("Floor at / floor from / floor to | Requested / arrived");
for (int i = 0; i < released.size(); i++) {
writer.println((previousFloor) + " / " +
(released.get(i).getPassengerRequest().getFloorFrom()) + " / " +
(released.get(i).getPassengerRequest().getFloorTo()) + " | " +
released.get(i).getPassengerRequest().getTimePressedButton() + " / " +
released.get(i).getTimeArrived());
previousFloor = released.get(i).getPassengerRequest().getFloorTo();
}
int startSeconds = TimeManip.timeToSeconds(new Time(8, 0, 0));
int finishSeconds = TimeManip.timeToSeconds(released.get(released.size() - 1).getTimeArrived());
int seconds = finishSeconds - startSeconds;
writer.println("Total cost (in seconds): " + Integer.toString(seconds));
writer.close();
} catch (FileNotFoundException e) {
System.out.println("File Not Found");
} catch (UnsupportedEncodingException e) {
System.out.println("Unsupported Encoding");
}
}
}