Question: Write a Java program to do the following: 1. Read in data from a text file that contains traffic data. Each line in the program

Write a Java program to do the following:

1. Read in data from a text file that contains traffic data. Each line in the program will contain an intersection ID (integer value) and the time it took a particular vehicle to cross the intersection (in seconds, integer value).

YOUR PROGRAM SHOULD NOT CONTAIN AN ABSOLUTE PATH TO THE FILE, ONLY THE FILE NAME (i.e., traffic.txt)

2.Read each line in the file and keep track of the number of vehicles that pass through an intersection and the number of accidents at an intersection. An accident occurs when it takes a car more than 500 seconds to cross the intersection.

3.Calculate and display the relative frequency of an accident per total number of vehicles that pass thru each intersection and the most dangerous intersections (in terms of most accidents and highest accident rate).

Requirements:

In addition to fulfilling the interaction described above your program must also

...

1. Have the main class named TrafficDataProcessor

2.Have a constant value, NUM_INTERSECTIONS, for the size of the array and set it to 12, the number of intersections.

3. Read from the file traffic.txt. This file as the following format with the first column containing the intersection ID and the second column containing the number of seconds a vehicle was in the intersection.

4. Calculate the number of accidents (i.e., if time in intersection is > 500) and accident rate of each intersection and save the result in an array.

5. Display the output in a manner consistent with sample interaction described below. You should display the number of vehicles, number of accidents and accident rate for each intersection. You should also determine the highest number of accidents and highest accident rate among all intersections. Do not worry if you show more or fewer decimal places with the results or if the alignment is off

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!