-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueueProgramTwo.java
More file actions
executable file
·99 lines (92 loc) · 3 KB
/
Copy pathQueueProgramTwo.java
File metadata and controls
executable file
·99 lines (92 loc) · 3 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import java.io.*;
import java.util.*;
public class QueueProgramTwo
{
public static void main(String[] args)
{
LinkedList<Passenger> que = new LinkedList<>();
PriorityQueue<Passenger> pq = new PriorityQueue<>();
File name = new File("PassengerInfo.txt");
try
{
BufferedReader input = new BufferedReader(new FileReader(name));
String text = "";
int x = 1;
String[] names;
String fN = "";
String lN = "";
String dest = "";
int time = 0;
while ((text = input.readLine()) != null)
{
if (x == 3)
{
String[] timeSplit = text.split(" ");
switch (timeSplit[1])
{
case "AM":
{
String[] temp = timeSplit[0].split(":");
String combine = temp[0] + temp[1];
time = Integer.parseInt(combine);
break;
}
case "PM":
{
String[] temp = timeSplit[0].split(":");
String combine = temp[0] + temp[1];
int tempInt;
if (temp[0].equals("12"))
{
tempInt = Integer.parseInt(combine);
} else
{
tempInt = Integer.parseInt(combine);
tempInt += 1200;
}
time = tempInt;
break;
}
}
Passenger ps = new Passenger(fN, lN, dest, text, time);
que.add(ps);
}
if (x == 2)
{
dest = text;
}
if (x == 1)
{
names = text.split(" ");
fN = names[0];
lN = names[1];
}
if (x < 3)
{
x++;
} else
{
x = 1;
}
}
} catch (IOException io)
{
System.err.println("File error");
}
while (que.peek() != null)
{
Passenger ps = (Passenger) que.remove();
if(ps.etdHour() ==0)
{
pq.add(ps);
}
System.out.println(ps.toString());
}
System.out.println();
while (pq.peek() != null)
{
Passenger ps = (Passenger) pq.remove();
System.out.println(ps.toString());
}
}
}