-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstructions.txt
85 lines (71 loc) · 4.4 KB
/
instructions.txt
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
Exercise - Section speed control
Section speed control is used in many countries to control traffic.
It is based on the vehicles passing two control gates that are several kilometres from each other.
At both points the license plate number of the vehicle and the time of passing the gate are recorded.
The average speed is calculated from the two time values.
If it exceeds the maximum allowed speed for the given section, then the driver has violated the traffic rules.
The section speed control measurement data of one of the lanes of a road section of length 10 km,
which is single-lane in both directions, are available.
The road section is closed, that is, vehicles cannot enter or exit it at any other point than the endpoint.
Text file measurements.txt contains the measurement data of a 1-hour measurement starting at 8 a.m. on a given day.
Each vehicle appears only once among the measurement data.
The measurement data of a given vehicle are given in one line separated by single spaces.
A line contains 9 pieces of data,
the license plate number of the vehicle (6 characters)
and the time recorded at the entry and exit points of the section in hour, minute, second, millisecond format.
(The file does not contain vehicle that did not have a recorded time at the entry or the exit point of the section.)
The number of lines is at most 1000. The data are ordered by the time recorded at the entry point. For example:
OXZ648 8 4 44 861 8 11 53 432
QUT385 8 4 53 376 8 9 28 185
QTS988 8 5 0 854 8 12 19 879
OTP604 8 5 2 263 8 12 21 288
According to the example, the vehicle with license plate number QTS988
passed the recorder at the entry point at 8:5:0.854 and passed the recorder at the exit point at 8:12:19.879.
8*3600+5*60+0+654/1000 == 29100.854
8*3600+12*60+19+879/1000 == 29539.879
29539.879 - 29100.854 == 439.025[s]/10000[m]
439.025/10 == 43.9025[s]/[km]
3600/43.9025 == 82[km/h]
Its average speed is 82 km/h, which is the distance travelled (10 km) divided by the elapsed time (0.1219 hour).
Write a java program that uses the data given in file measurements.txt to answer the following questions.
If an exercise requires displaying data on the screen, display the exercise number before displaying the result
(for example: Exercise 3.).
If you request data from the user, display the nature of the requested data on the screen.
Display the results and communicate with the user according to the example given at the end of the exercise.
1. Read and store the data of file measurements.txt.
2. Display the number of vehicles whose data were recorded in the measurement on the screen.
3. From the available data, determine the number of vehicles that passed the exit point of the section before 9 o’clock.
Display the number on the screen.
4. Request a time given in hour minute format from the user.
4a. Determine the number of vehicles that passed the entry point in the given minute.
If in the given minute no vehicle passed the entry point, then display value 0.
4b. Determine the traffic intensity :
which is the number of vehicle on the road section in the minute that starts at the given minute
(e.g. if the given hour minute is 08:09, then between 08:09:00.000-08:09:59.999)
divided by the length of the road section.
Display the value in decimal fraction format.
5. Find the speed of the vehicle with the highest average speed
and the number of vehicles overtaken by it in the measured section.
If there are several highest average speeds, it is enough to display only one of them.
Display the license plate number of the vehicle,
the average speed as an integer and the number of overtaken vehicles.
6. Determine what percent of the vehicles exceeded the maximum speed limit on the measured section (90 km/h)
with their average speed.
Display the result in decimal number format according to the example.
7. Extra task: At the end write the results into a .txt file.
Example for the textual output:
Exercise 2.
The data of 687 vehicles were recorded in the measurement.
Exercise 3.
Before 9 o'clock 603 vehicles passed the exit point recorder.
Exercise 4.
Enter an hour and minute value: 8 20
a. The number of vehicle that passed the entry point recorder: 12
b. The traffic intensity: 9,4
Exercise 5.
The data of the vehicle with the highest speed are
license plate number: OKL564
average speed: 137 km/h
number of overtaken vehicles: 33
Exercise 6.
11,94% percent of the vehicles were speeding.