Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a Java program to do the following: 1. Read in data from a text file that

ID: 3818001 • Letter: W

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 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

Explanation / Answer

Source Code: Save it in a file name with TrafficDataProcessor.java along with inline comments explaining the source code

#########################################################################################

Sample input text file : traffic.txt

First digit is intersection number and starts from 0 to 11 for the given 12 number of intersection points in the problem statement

#####################################################################################

#######################################################################################

How to run the code:

Step 1: Save the source code in a file with name "TrafficDataProcessor.java"

Step 2: Save the sample data input in a file with name "traffic.txt" in the same directory as above in step 1.

Step 3: Open a command prompt and make sure that jre (java run time environment) is installed.

Step 4: Compile the code: "javac TrafficDataProcessor.java"

Step 5: Execute the code: "java TrafficDataProcessor"

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote