-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCustomerList.java
More file actions
213 lines (146 loc) · 4.23 KB
/
CustomerList.java
File metadata and controls
213 lines (146 loc) · 4.23 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;
public class CustomerList {
public int servetime;
public CustomerNode first;
public int longestLength;
public int numServed;
public ArrayList<Query> queryList = new ArrayList<Query>();
//initialize customerList
public CustomerList() {
first = null;
}
//check if empty
public Boolean isEmpty() {
if (first == null) {
return true;
}
else {
return false;
}
}
//count length
public int currentLength() {
int ans = 0;
CustomerNode current = first;
while (current != null) {
ans++;
current = current.next;
}
return ans;
}
//enqueue
public void enqueue(CustomerNode addition) {
addition.next = null;
//set current to first
CustomerNode current = first;
//special case since first doesnt have .next
if (current == null) {
first = addition;
return;
}
//while current is not the last element
while (current.next != null) {
//increment current
current = current.next;
}
//add the addition at the end of the list. addition.next defaults to null
current.next = addition;
}
public CustomerNode dequeue() {
CustomerNode ans = first;
if (first.next == null) {
first = null;
}
else {
first = first.next;
}
return ans;
}
public void displayCustomers() {
CustomerNode current = first;
//iterate through and display
while (current != null) {
System.out.printf("%-10s%-20s%s\n", "ID: "+ current.id, " Arrival Time: "+ current.arrivalTime, " Seconds: " +current.seconds);
current = current.next;
}
}
public void displayQueries() {
for (int i = 0; i < queryList.size(); i ++) {
System.out.printf("%-30s%-10d\n", queryList.get(i).name, queryList.get(i).queryCode);
}
}
public void createList(File customers) throws FileNotFoundException {
try {
Scanner custscan = new Scanner(customers);
ArrayList<String> custContent = new ArrayList<String>();
servetime = Integer.parseInt(custscan.nextLine());
//while file has not been exhausted
while (custscan.hasNextLine()) {
String line = custscan.nextLine();
//skip over blank lines
if (line.isEmpty()) {
continue;
}
//disregard the label, store only the data
String[] split = line.split(" ");
custContent.add(split[1]);
}
//use the collected data to make new CustomerNodes
for (int i = 0; i < custContent.size(); i+=2) {
CustomerNode a = new CustomerNode();
a.id = Integer.parseInt(custContent.get(i));
a.arrivalTime = custContent.get(i+1);
a.timeInSeconds(a.arrivalTime);
this.enqueue(a);
}
custscan.close();
}
//catch is file is not found
catch (FileNotFoundException err) {
System.out.println("File not found");
}
}
public void getQueries(File queries) throws FileNotFoundException {
//scan info and tokenize
ArrayList<String> queryContent = new ArrayList<String>();
Scanner querscan = new Scanner(queries);
while (querscan.hasNextLine()) {
String line = querscan.nextLine();
String[] split = line.split(" ");
for (int i = 0; i < split.length; i++) {
queryContent.add(split[i]);
}
}
querscan.close();
//create query objects from tokens
for (int i = 0; i < queryContent.size(); i ++) {
Query a = new Query();
if (queryContent.get(i).equals("NUMBER-OF-CUSTOMERS-SERVED")) {
a.name = "NUMBER-OF-CUSTOMERS-SERVED";
a.queryCode = 1;
}
else if (queryContent.get(i).equals("LONGEST-BREAK-LENGTH")) {
a.name = "LONGEST-BREAK-LENGTH";
a.queryCode = 2;
}
else if (queryContent.get(i).equals("TOTAL-IDLE-TIME")) {
a.name = "TOTAL-IDLE-TIME";
a.queryCode = 3;
}
else if (queryContent.get(i).equals("MAXIMUM-NUMBER-OF-PEOPLE-IN-QUEUE-AT-ANY-TIME")) {
a.name = "MAXIMUM-NUMBER-OF-PEOPLE-IN-QUEUE-AT-ANY-TIME";
a.queryCode = 4;
}
else if (queryContent.get(i).equals("WAITING-TIME-OF")) {
a.name = "WAITING-TIME-OF";
a.queryCode = 5;
a.CustomerID = Integer.parseInt(queryContent.get(i+1));
i++;
}
queryList.add(a);
}
}
}