Java代写:CSCI2110 Analyzing Data from a Road Traffic Meter

根据两个测距仪传感器采集到的时间和车速数据,推测道路上的汽车型号。

Purpose

The purpose of this assignment is to refresh your programming skills and get you programming as quickly as possible.

As discussed in class and the first tutorial, for each problem you will be provided with a description of the problem and a JUnit test class to test your code. A similar JUnit test class will be used to evaluate your code. You can use Eclipse or other IDEs to run the JUnit test class to test your code.

Your code must compile. If it does not compile, you will receive a 0 on the assignment.

Problem: Analyzing Data from a Road Traffic Meter

To analyze how much traffic is on the street, city planners use a Road Traffic Meter, as shown in the figure below:

The traffic meter consists of two air hoses lying across the lane of traffic. Every time the wheels of a vehicle roll over both hoses in quick succession, the meter logs the event as one axle of a vehicle. Two pieces of information are logged for each event: the time (in milliseconds) and the speed the axle was traveling at (in kilometers per hour). The traffic meter produces a log of axle events that look like this:

97205795 51
97205995 52
97207123 45
97207347 44
...

where each line corresponds to a single axle event and is denoted by the time of crossing and speed.

However, traffic planners need to know how many cars and heavy trucks are using the street. Your task is to write a program that processes the log and converts the log of axles to a log of cars and trucks that have crossed the traffic meter.

Write a program called VehicleCounter.java that reads in a log of axles (as exemplified above) and outputs the corresponding list of cars and heavy trucks. Your VehicleCounter class must implement the provided TrafficReporter interface. This is because your program will be tested via this interface. The interface contains a single method:

1
public ArrayList computeTraffic(Scanner input);

This method must perform the required computation.

Input

The method takes a Scanner object, which contains 0 or more lines of text from the log produced by a traffic meter. Each line denotes a single event of an axle crossing the traffic meter. Each line consists of

  • an integer of type long, denoting the time in milliseconds; and
  • an integer of type int, denoting the speed of the axle in kilometers per hour.

You may assume that there are no errors in the input.

Hint: Use the Scanner object to easily parse the input by using the methods such as hasNextLong(), nextLong(), and nextInt(), on the Scanner object.

Semantics

The input log will contain a sequence of axles, corresponding to zero or more vehicles driving down the street. Your vehicle counter must distinguish between two classes of traffic:

Cars and light trucks are vehicles that have exactly two axles, which are at least 186cm apart.

Heavy trucks are vehicles that have at least three axles, with one or more close consecutive axles at the front and one or more close consecutive axles on the back. Two axles are close if they are less than 186cm apart.

The distance between axles can be computed using the general formula

distance = speed * time

where speed is the average of the two axle speeds and time is the positive difference between the arrival times of the two axles. Note: The speed of the axles is given in km/h, the time of arrival is given in milliseconds, and the minimum distance is in centimeters. You will need to convert the values to common units in order to get correct results.

Output

The method should return an ArrayList of Strings denoting the class of vehicle for each set of axles in the input log. If the axles correspond to the car or light truck, the corresponding String is

T: Car or light truck

and, if the axles in the input log correspond to a heavy truck, the corresponding String is

T: Heavy truck, F R

where
T is the time, rounded down to the nearest second, of the vehicle’s first axle crossing the traffic meter.
F is the number of axles at the front of a heavy truck.
R is the number of axles at the rear of a heavy truck.

Examples

Below are a sequence of examples and the corresponding output.

Sample Input

502788 32
503612 33
503775 34
560933 37
561479 36
595629 41
596044 42
650172 56
650780 55
650878 54
650978 53

Sample Output

502: Heavy truck, 1 2
560: Car or light truck
595: Car or light truck
650: Heavy truck, 1 3

Hints and Suggestions

  • Your code must compile. If it does not compile, you will receive a 0 on the assignment.

  • Your code must be well commented and indented. Please see the Assignments section for this course on Brightspace for Code Style Guidelines.

  • You may assume that all input will be correct. You do not need to handle incorrect input, for now.

  • The problem in this assignment has a short solution (50 lines of code).

  • Be sure to test your programs using the provided JUnit test class.

Grading

The assignment will be graded based on three criteria:

Functionality

“Does it work according to specifications?”. This is determined in an auto- mated fashion by running your program on a number of inputs and ensuring that the outputs match the expected outputs. The score is determined based on the number of tests that your program passes. So, if your program passes t tests, you will receive T that proportion of the marks.

Quality of Solution

“Is it a good solution?” This considers whether the solution is correct, efficient, covers boundary conditions, does not have any obvious bugs, etc. This is determined by visual inspection of the code. Initially full marks are given to each solution and marks are deducted based on faults found in the solution.

Code Clarity

“Is it well written?” This considers whether the solution is properly formatted, well documented, and follows coding style guidelines.

If your program does not compile, it is considered non-functional and of extremely poor quality, meaning you will receive 0 for the solution.

What to Hand In

Submit the source files for your program in a zip file (.zip). You should have at least one source file: VehicleCounter.java. If you are using Eclipse, we recommend that you submit the entire project bundle. Submission is to be done via Brightspace. Your code must compile. If it does not compile, you will receive a 0 on the assignment.