-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDemo_for_stage1a
363 lines (352 loc) · 14.3 KB
/
Demo_for_stage1a
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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
Script started on Mon Nov 14 13:31:43 2016
ds_for_stage1amactop: ~/Documents/UR/y3s1/cs322/proj/code/cs322-traffic-projdavid@mactop:~/Documents/UR/y3s1/cs322/proj/code/cs322-traffic-proj$ cat unix_comman
# How to use the current file:
# Step 1: Copy and paste current file into a file with the name
# unix_commands_for_nov2
# and save the resulting file in the iMac's Desktop directory
# Step 2: Preserve that file using the Unix command:
# cp -p unix_commands_for_nov2 save_unix_commands_for_nov2
# Step 3: Edit the file unix_commands_for_nov2 replacing File2, File3, etc.,
# with your choice of class names; see NOTE1 below to understand
# what this step means as File2, File 3, etc.
# Step 4: Edit the file unix_commands_for_nov2 replacing "data1" with
# your choice of "data2", etc., IF you wish to make such a change;
# see NOTE2 below for what this step means as "data1", etc.
# Step 5: Change the "mode" of the resulting file so the file becomes
# executable under the Unix command interpreter, via the
# following Unix command:
# chmod +x unix_commands_for_nov2
# Step 6: Try an experiment using the resulting file:
# ./unix_commands_for_nov2
# Scroll up and down the Unix window to see if that experiment
# was as successful as you wanted it to be; if it is,
# go to Step 7. (Otherwise go back to Step 3 or Step 4.)
# Step 7: Do the following Unix to obtain a demo file:
# script
# cat unix_commands_for_nov2
# ./unix_commands_for_nov2
# exit
# col -b < typescript > Demo_for_nov2_2016
# Step 8: Submit all your *java files and all your *data* files and also
# the file Demo_for_nov2_2016 to the folder for you team for
# the top-level logic project due on Friday, where you submit
# all those files during the lab on Wed, Nov 2, to show the
# current state of your iterative enhancement.
#!/bin/csh
echo "<UNIX-PROMPT> pwd"
pwd
echo "<UNIX-PROMPT> ls -tl *java"
ls -tl *java
echo "<UNIX-PROMPT> wc *java"
wc *java
echo "<UNIX-PROMPT> cat TrafficTesterView.java"
cat TrafficTesterView.java
# NOTE1 On Wed, Nov 2, replace File2, File3, etc., by appropriate
# Java class names to demonstrate the current stage of
# your iterative enhancement. Use as many or as few such
# classes as you decide would best demonstrate the
# current stage of your iterative enhancement.
#echo "<UNIX-PROMPT> cat TrafficTesterModel.java"
#cat TrafficTesterModel.java
#echo "<UNIX-PROMPT> cat Grid.java"
#cat Grid.java
#echo "<UNIX-PROMPT> cat Intersection.java"
#cat Intersection.java
#echo "<UNIX-PROMPT> cat Lane.java"
#cat Lane.java
#echo "<UNIX-PROMPT> cat Car.java"
#cat Car.java
echo "<UNIX-PROMPT> /bin/rm *class"
/bin/rm *class
echo "<UNIX-PROMPT> javac TrafficTesterView.java"
javac TrafficTesterView.java
echo "<UNIX-PROMPT> ls -tl *class"
ls -tl *class
# NOTE2 On Wed, Nov 2, replace "data1" below by one of "data2" (or
# "data3", etc.), if you wish, according to your decision on
# what would best demonstrate the current stage of your
# iterative enhancement.
echo "<UNIX-PROMPT> cat data11_for_TrafficTesterView"
cat data11_for_TrafficTesterView
echo "<UNIX-PROMPT> java TrafficTesterView < data11_for_TrafficTesterView"
java TrafficTesterView < data11_for_TrafficTesterView
_for_stage1aop: ~/Documents/UR/y3s1/cs322/proj/code/cs322-traffic-projdavid@mactop:~/Documents/UR/y3s1/cs322/proj/code/cs322-traffic-proj$ ./uniKx_commands
<UNIX-PROMPT> pwd
/Users/david/Documents/UR/y3s1/cs322/proj/code/cs322-traffic-proj
<UNIX-PROMPT> ls -tl *java
-rwxr-xr-x 1 david staff 7948 Nov 14 13:20 13_20_nov14_2016_TrafficTesterView.java
-rwxr-xr-x 1 david staff 7948 Nov 14 13:20 TrafficTesterView.java
-rwxr-xr-x 1 david staff 10024 Nov 14 13:12 Grid.java
-rwxr-xr-x 1 david staff 8774 Nov 14 13:12 Intersection.java
-rwxr-xr-x 1 david staff 1818 Nov 14 13:12 Lane.java
-rwxr-xr-x 1 david staff 1956 Nov 11 13:33 Car.java
-rwxr-xr-x 1 david staff 1561 Nov 11 13:33 TrafficTesterModel.java
<UNIX-PROMPT> wc *java
190 892 7948 13_20_nov14_2016_TrafficTesterView.java
55 181 1956 Car.java
243 999 10024 Grid.java
227 798 8774 Intersection.java
62 191 1818 Lane.java
42 138 1561 TrafficTesterModel.java
190 892 7948 TrafficTesterView.java
1009 4091 40029 total
<UNIX-PROMPT> cat TrafficTesterView.java
// Programmer: Arthur Charlesworth (c) Copyright 2016
// Modified by GOATS team: Alex David Rex Tom Zihao
// *****************************************************************************
// *****************************************************************************
// **** TrafficTesterView
// *****************************************************************************
// *****************************************************************************
// Latest Enhancement: Read in new data format, with print statements
// NOTE: A lane has the same coordinates as the intersection the lane aims at.
// Throughout the rest of the semester, make sure that
// intersections of a grid are processed in exactly the following order:
// row 1 intersections, from left to right
// row 2 intersections, from left to right, etc, for all rows.
// In an actual simulation, that process should be repeated (in that specific
// order) as many times as necessary for the desired length of the simulation.
// But, for simplicity, the initial tester software students build should
// only show the first iteration of the above process, that is, only one
// processing of each of the intersections.
//
// The format of the data to be used with the program in this file
// is show, via an example, at the end of this file.
import java.util.*;
public class TrafficTesterView {
// NOTE: Just to keep the current tester program really simple,
// the following constants are not encapsulated within two classes, Direction
// and Turn, according to appropriate Information Hiding:
static final int SOUTHWARD = 0;
static final int EASTWARD = 1;
static final int NORTHWARD = 2;
static final int WESTWARD = 3;
static final int NEVER_TURN = 0;
static final int TURN_RIGHTWARD = 1;
static final int TURN_LEFTWARD = -1;
public static void main(String[] args) {
Scanner console = new Scanner(System.in);
console.nextLine();
int numIntersectionsInOneDirection = console.nextInt();
System.out.print("The number of intersections in one direction ");
System.out.println("is: " + numIntersectionsInOneDirection);
console.nextLine();
console.nextLine();
int lengthOfSimulation = console.nextInt();
System.out.print("The length of the simulation ");
System.out.println("is: " + lengthOfSimulation);
console.nextLine();
console.nextLine();
int maxLaneCapacity = console.nextInt();
System.out.print("The maximum capacity of a lane is ");
System.out.println("is: " + maxLaneCapacity);
console.nextLine();
console.nextLine();
int minTimeToTravelLane = console.nextInt();
System.out.print("The minimum time to travel a lane ");
System.out.println("is: " + minTimeToTravelLane);
console.nextLine();
console.nextLine();
int maxQuarterRoundaboutCapacity = console.nextInt();
System.out.print("The maximum capacity of a quarter of a roundabout ");
System.out.println("is: " + maxQuarterRoundaboutCapacity);
console.nextLine();
console.nextLine();
int minTimeToTravelQuarterRoundabout = console.nextInt();
System.out.print("The minimum time to travel a quarter of a roundabout ");
System.out.println("is: " + minTimeToTravelQuarterRoundabout);
console.nextLine();
console.nextLine();
int numberOfCars = console.nextInt();
System.out.println("The number of cars is: " + numberOfCars);
int carID;
int row;
int col;
int laneDirectionCode;
int numBlocksBeforeTurning;
int turnDirectionCode;
ArrayList< ArrayList<Integer> > carParameters;
carParameters = new ArrayList< ArrayList<Integer> >();
for (int i = 1; i <= numberOfCars; i++) {
console.nextLine();
console.nextLine();
carID = console.nextInt();
System.out.println("Car #" + carID);
console.nextLine();
console.nextLine();
col = console.nextInt();
console.nextLine();
console.nextLine();
row = console.nextInt();
console.nextLine();
console.nextLine();
laneDirectionCode = console.nextInt();
console.nextLine();
console.nextLine();
numBlocksBeforeTurning = console.nextInt();
console.nextLine();
console.nextLine();
turnDirectionCode = console.nextInt();
ArrayList<Integer> currentParams = new ArrayList<Integer>();
currentParams.add(carID);
currentParams.add(row);
currentParams.add(col);
currentParams.add(laneDirectionCode);
currentParams.add(numBlocksBeforeTurning);
currentParams.add(turnDirectionCode);
carParameters.add(currentParams);
System.out.println(" is born in the lane located at col " + col +
" and row " + row + ", that aims " +
convertToLaneDirection(laneDirectionCode) + ",");
System.out.println(" and has " + numBlocksBeforeTurning +
" block(s) to go before turning");
System.out.println(" and plans to " +
convertToTurnDirection(turnDirectionCode));
} // end for
//System.out.println("In TrafficTesterView: constructing a Traffic"+
// "TesterModel");
//TrafficTesterModel sim = new TrafficTesterModel(
// numIntersectionsInOneDirection,numIntersectionsInOneDirection,
// carParameters);
//System.out.println("In TrafficTesterView: running the TrafficTesterModel");
//sim.run();
} // main
public static String convertToLaneDirection(int laneDirectionCode) {
if (laneDirectionCode == SOUTHWARD) return "SOUTHWARD";
if (laneDirectionCode == EASTWARD) return "EASTWARD";
if (laneDirectionCode == NORTHWARD) return "NORTHWARD";
if (laneDirectionCode == WESTWARD) return "WESTWARD";
return "ILLEGAL laneDirectionCode!!!";
} // convertToLaneDirection
public static String convertToTurnDirection(int turnDirectionCode) {
if (turnDirectionCode == NEVER_TURN) return "NEVER_TURN";
if (turnDirectionCode == TURN_RIGHTWARD) return "TURN_RIGHTWARD";
if (turnDirectionCode == TURN_LEFTWARD) return "TURN_LEFTWARD";
return "ILLEGAL turnDirectionCode!!!";
} // convertToTurnDirection
} // TrafficTesterView
////////////////// Example of sample use of the above program //////////////////
// except for the fact that all the following lines have been made comments, //
// and also the actual phrase "additional blocks to travel" in the data //
// shown below has been shortened to the phrase "additional blocks" to fit //
// the lines below into the required 80-columns per line. //
////////////////////////////////////////////////////////////////////////////////
//numIntersectionsInOneDirection:
//1
//number of cars created for the test:
//2
//car number:
//1
//born in the lane that is positioned at col:
//1
//born in the lane that is positioned at row:
//1
//born in the lane that is oriented in direction:
//0
//additional blocks prior to turning (-1 means the car will never turn):
//0
//direction the car will turn, when the car turns:
//1
//car number:
//2
//born in the lane that is positioned at col:
//1
//born in the lane that is positioned at row:
//1
//born in the lane that is oriented in direction:
//3
//additional blocks prior to turning (-1 means the car will never turn):
//-1
//direction the car will turn, when the car turns:
//0
//hopper2{acharles}2484: java TrafficTesterView < data1_for_TrafficTesterView
//The number of intersections in one direction is: 1
//The number of cars is: 2
//Car #1
// is born in the lane located at col 1 and row 1, that aims SOUTHWARD,
// and has 0 block(s) to go before turning
// and plans to TURN_RIGHTWARD
//Car #2
// is born in the lane located at col 1 and row 1, that aims WESTWARD,
// and has -1 block(s) to go before turning
// and plans to NEVER_TURN
//
<UNIX-PROMPT> /bin/rm *class
rm: *class: No such file or directory
<UNIX-PROMPT> javac TrafficTesterView.java
<UNIX-PROMPT> ls -tl *class
-rw-r--r-- 1 david staff 3064 Nov 14 13:32 TrafficTesterView.class
<UNIX-PROMPT> cat data11_for_TrafficTesterView
numIntersectionsInOneDirection:
2
lengthOfSimulation:
6
maxLaneCapacity
2
minTimeToTravelLane
2
maxQuarterRoundaboutCapacity
2
minTimeToTravelQuarterRoundabout
2
number of cars created for the test:
3
car number:
1
born in the lane that is positioned at col:
1
born in the lane that is positioned at row:
1
born in the lane that is oriented in direction:
2
additional blocks to travel prior to turning (-1 means the car will never turn):
0
direction the car will turn, when the car turns:
1
car number:
2
born in the lane that is positioned at col:
2
born in the lane that is positioned at row:
1
born in the lane that is oriented in direction:
1
additional blocks to travel prior to turning (-1 means the car will never turn):
-1
direction the car will turn, when the car turns:
0
car number:
3
born in the lane that is positioned at col:
2
born in the lane that is positioned at row:
1
born in the lane that is oriented in direction:
1
additional blocks to travel prior to turning (-1 means the car will never turn):
-1
direction the car will turn, when the car turns:
0
<UNIX-PROMPT> java TrafficTesterView < data11_for_TrafficTesterView
The number of intersections in one direction is: 2
The length of the simulation is: 6
The maximum capacity of a lane is is: 2
The minimum time to travel a lane is: 2
The maximum capacity of a quarter of a roundabout is: 2
The minimum time to travel a quarter of a roundabout is: 2
The number of cars is: 3
Car #1
is born in the lane located at col 1 and row 1, that aims NORTHWARD,
and has 0 block(s) to go before turning
and plans to TURN_RIGHTWARD
Car #2
is born in the lane located at col 2 and row 1, that aims EASTWARD,
and has -1 block(s) to go before turning
and plans to NEVER_TURN
Car #3
is born in the lane located at col 2 and row 1, that aims EASTWARD,
and has -1 block(s) to go before turning
and plans to NEVER_TURN
0;david@mactop: ~/Documents/UR/y3s1/cs322/proj/code/cs322-traffic-projdavid@mactop:~/Documents/UR/y3s1/cs322/proj/code/cs322-traffic-proj$ exit
exit
Script done on Mon Nov 14 13:32:07 2016