Write a program to help analyze data on speeding tickets

Assignment Help JAVA Programming
Reference no: EM131418379

Java Programming Assignment: Array Implementation

NOTE: This assignment will be more challenging than the previous assignments, so make sure to start early and allocate enough time to complete it, including time you might need to seek any necessary help.

Since this is the last program, the program may not be submitted more than 1 day late!

Problem Summary

A local city would like you to write a program to help them analyze data on speeding tickets. City police have collected information about the speeding violations. They store data about each ticket issued during a one week period in a text data file. Data collected for each ticket includes the vehicle license plate number, the speed limit, and the clocked speed. From past data, the police department knows that it will not issue more than 200 tickets per week.

You may assume all data in input data file is valid data (i.e. formatted correctly), but you must verify that the file exists (i.e. can be opened). If the file does not exist, the program will loop until you enter the filename for a file that can be opened.

Sample input data file lines:
BBB222  50  60
XYZ123  40  45
A1B2C3  30  51

The police department would like you to write a program to read the file, calculate the fines to assess, and generate several reports. The program will:

• Read the data from the file, line by line, and store the data into an array that holds ticket data objects. This array will hold a maximum of 200 ticket data objects.

• Calculate the speeding ticket fines to assess, based on the ticket data, and store the fines into a second array that holds double values. This array will be sized to the number of tickets issued.

• Produce an output file, containing the vehicle license plate numbers and speeding fines.

• Analyze the fines to determine the high, low, and average fines, and display the results.

Here are the formulas the city uses for calculating a speeding ticket fine:

Ticket Fine = Court costs ($45.00) + a fee for each mile per hour (MPH) by which the speed limit was exceeded The fee will be levied as follows:

MPH Over Speed Limit

Fee per MPH Over Speed Limit (for all MPH over limit)

up to 10

$ 4.25

over 10 and up to 20

$ 6.00

over 20

$ 8.10

You must define constants to hold all fixed values (court costs, MPH over speed limits, and fees per MPH) in the above chart within your method that calculates the fines.

Program Requirements

This program will implement two different types of arrays. One array will hold ticket objects, and will require an implementation class. The other array will contain primitive data type double values, and will not require an implementation class.

NOTE: The ticket array and the fines array will be parallel arrays. This means that the fine will be stored into the fines array using the same index as the ticket object in the ticket array.

NOTE: For an example of a Java program implementing arrays, see Online Content section 15.10.

Required Classes and Methods

Three separate classes will be required for this program.

• A class to define a SpeedingTicket object
• A class to implement the object array (to hold SpeedingTicket objects)
• A main class to run the program

1. Create a new Java NetBeans project, named as follows:

LastnameJavaAssn8
For example: SmithJavaAssn8

2. Define a Java class with properties and methods for a speeding ticket object, named:

SpeedingTicket

The class will have the following private data properties:

- vehicle license plate number (a 6-character String)
- the speed limit
- the clocked speed

Within the SpeedingTicket class:

• Define a constructor, with parameters for each data property.

o Use the parameters to initialize the values.

• Define getters for each data property.

3. Define a second class that will implement the ticket array for this program, named:

TicketArrayImpl

The class will have the following public data properties:

- A static constant array size (maximum items that can be held in the array) set to 200 The class will have the following private data properties:

- A ticket data array (to hold SpeedingTicket objects)

- A count of actual ticket objects stored

Note: The data property definitions will only define the array reference variable.

It will not create the array object.

Within the TicketArraysImpl class:

• Define a constructor that will:

o Instantiate a ticket array object (using new to initialize the array reference variable and the constant array size)
o Initialize the count of tickets stored to 0

• Define an instance method to add one SpeedingTicket object to the ticket data array. The method will:

o Have one parameter, the ticket object to add
o Test to see if the array is full

o If the array is full, will throw an ArrayIndexOutOfBoundsException

• Include a message to pass to the exception handler that states the array is full and stating which license cannot be added.

o Otherwise, store the ticket object into the array and increase the ticket count

• Define a method to read all the data from the input file and store the ticket data by adding

SpeedingTicket objects into the array. The method will:

o Have one parameter: the name of the data input file (String)
o Return an int value

o If the file was opened successfully, the method will return the number of tickets stored in the array.
o Otherwise, it will return 0, to indicate the file could not be opened/read.

o Implement code to try to open the input data file. If the file opened:

o Display a message that the program is reading the file data
o In a loop:

- Read the three data items from one line of data in the input data file
- Call the constructor to create a new SpeedingTicket object.
- Try to call the instance method to add the ticket object to the ticket data array (this is an instance method of the TicketArrayImpl class)
- Catch any thrown ArrayIndexOutOfBoundsException exceptions.

o Display the message passed back via the throw.
o Also display a message that no more data will be read from the file.
o Set a value to exit the loop (so no more data will be read). Loop until there is no more file data or an exception is thrown.

o Close file.

o Display the number of SpeedingTicket objects stored in the ticket data array.

o Catch any FileNotFoundException exceptions. When caught:

- Display a message that explains which file could not be opened.

o Return the count of tickets stored in the array.

• Define a method to calculate and store values in the fines array. The method will:

o Have one parameter, the empty fines array
o Define constants for all fixed values in the calculations (from page 1 of this assignment).
o For each ticket stored in the ticket array:

o Access the clockedSpeed and speedLimit data stored in the object using getters.
o Calculate the ticket fine.
o Store the calculated fine in the fines array.

• Define an instance method to produce a fines report.

The method will create an output file with the fines report. The method should:

o Have one parameter, the fines array

o Read the filename for the report output file from the user.

o Try to open the report output file

o If the file opened successfully, generate a report and write it to the output file.

o The output file will contain a list of vehicle license plate numbers (accessed via a getter) and the fine associated with that license, with the fines right-aligned on the decimal point.

o The last line of the output file will contain the total of all fines collected, right- aligned on the decimal point, with the fines listed above it.

Sample output file
BBB222   87.50
XYZ123   66.25
A1B2C3   215.10
Total       368.85

o Catch any FileIOException exceptions. When caught:
o Display a message that explains which file could not be opened and that a fines report will not be generated.

4. Define a third (main) class named:

TicketAnalysis
Within the TicketAnalysis class:

• Define three static methods to:

o Determine and return the lowest fine amount
o Calculate and return the average fine amount
o Determine and return the highest fine amount

Each will have the fines array and count of fines in the array as parameters.

• Define a static method to display a ticket summary, using the previously defined static methods to calculate the low, high, and average fines.

o Parameters: the fines array and count of fines in the array

o Ticket summary will be displayed as shown in the sample output on the next page, with all figures will be right-aligned on the decimal point.

• Define a main method to:

o Display a description of what the program will do to the user.
o In a loop (outer loop):
o Create a new object of the TickeArraysImpl class.
o In a loop (inner loop):

- Read the filename for the input data file from the user.

- Using the object, call the instance method to read and store the data from the input file (sends a message to the TicketArraysImpl object). Loop until the method returns a number other than 0, indicating the file was read (and that the ticket data array now has ticket data stored in it).

o Display a message to the user, that the program is calculating the fines.
o Define an array (to hold double fines), the same size as the array for ticket objects.
o Uses the TicketArraysImpl object to call:

- The instance method to calculate the fines and store them in the array
- The instance method to produce a fines report

o Execute the static method to display a ticket summary.

o Ask the user whether to run the program again, using a different input file. Loop until the user says s/he does not want to run the program again.

WARNING: The objects, classes, and methods must be implemented exactly as specified above. If your program produces correct output, but you did not create and use the objects as specified, and implement the required classes and methods, you will lose a significant number of points.

See last page of the file for outline of code for the three required classes.

5. The program must follow the CS210 Coding Standards from Content section 6.10. Be sure to include the following comments:

o Comments at the top of each code file describing what the class does
o Include tags with the author's name (i.e. your full name) and the version of the code (e.g. Java Assn 4, version 1.0)
o Comments at the top of each method, describing what the method does Include tags with names and descriptions of each parameter and return value.

Testing

You will need to create test data files to test your program. In combination, all your test data files should test every possible execution path within your code, including erroneous data which cause exceptions.

Before you submit your project, add your all files you used to test your program in the top level of your project directory (and add a number to the end of each file, if there are multiple test data files).

File examples: datafile1.txt

datafile2.txt (numbered, if multiple data files tested)

Submission

This programming assignment is due by midnight of the date listed in the Course Assignments by Week.

REMINDER: Programs submitted that do not compile without errors will not be accepted.

Again, you will submit a single zip file containing all of the files in your project.

• First export your project from NetBeans, as detailed in previous assignments

o Name your export file in the following format:

<lastname>Assn<x>.zip

For example: SmithAssn8.zip

NOTE: Save this zip file to some other directory, not your project directory.

• Then submit your .zip file to the Java Prog Assn 8 assignment submission folder (located under the Assignments/Dropbox tab in the online course).

o Warning: Only NetBeans export files will be accepted.

Do not use any other kind of archive or zip utility.

Reference no: EM131418379

Questions Cloud

Create an informative web page about any topic : Create an informative web page about any topic that interests you. Make sure that you write the content (the paragraphs of information about your topic) yourself.
Describing the internal recruiting and selection processes : For organizations to be successful, there must be a clear-cut policy describing the internal recruiting and selection processes for internal promotions. For this discussion, assume you work for CapraTek (fictional company)  and you have been asked..
Performance appraisal process : What are some areas of the performance appraisal process that might have broken down?
How can you analyze the problem : How can you analyze the problem? What variable would you examine? Which members of the staff would you call on to help analyze and improve the situation
Write a program to help analyze data on speeding tickets : CS210- A local city would like you to write a program to help them analyze data on speeding tickets. City police have collected information about the speeding violations.
Draw a network diagram of a suitable gate arrangement : These devices are to be used in conjunction with a logic network of AND and OR gates and the output of the network is to be 1 when two or more of the sensing devices are producing signals of 1 - Draw a network diagram of a suitable gate arrangemen..
Conduct a job analysis : a. Why is it important for a manager to be able to conduct a job analysis? What are the negative outcomes that would result from not understanding the jobs of those reporting to the manager?
How the government affect a health care organization : In a 1-2 page paper, discuss how the government, the media, and the public affect a health care organization's integration of data
What is tje temperature drop of the air : Air expands adiabatically through a nozzle from a negligible initial velocity to a final velocity of 325 ms-1. What is tje temperature drop of the air, if ar is assumed to be an ideal gas for which Cp= (7/2)R?

Reviews

Write a Review

 

JAVA Programming Questions & Answers

  Java program that will add the corresponding elements

Develop a Java program that will add the corresponding elements of two 1-dimensional arrays X and Y to produce the 1-dimensional array Z. Arrays X, Y, Z have the same dimension [M].

  Prints out your gradebook entries

Create a new gradebook entry for four different CSCI courses. Must use a constructor to initialize the course name - Prints out your gradebook entries

  Create a class called employee with name idno address and

create a class called employee with name idno address and phone number as attributes. create the setter and getter

  Create a gui with 3 jtextfield,one jtextarea and display it

The user should be able to input in the text fields the loan amount, interest rate, and term, or input the loan amount in a text field and then select from the combo box the type of loan.

  Movie should be represented

Each movie should be represented by an object of type Movie. The Movie class must provide two public fields: title and category. Both of these fields should be Strings. The class should also provide a

  Write a program to track their hotel occupancy for hotels

The Paris Hotels Company needs a computer program to track their hotel occupancy for the hotels in their chain. Write a Java program that calculates the occupancy rate for each floor of a hotel.

  Sentence patterns and verb formulas

Provide the sentence pattern. Write out the sentence pattern - then write out the tense of the verb and provide the formula.

  Explain at least three scenarios where he is wrong

Explain at least three scenarios where he is wrong, that is, where users other than a file's owner need some kind of allowed access privileges

  Give an example of an exception

A. Give an example of an exception that could be generated outside your code but caught within your code

  Find and display the max value and the index of the max

Find and display the max value and the index of this max. Display the Even elements. Sorts and displays the numbers from lowest to highest using Arrays.sort() method from java.util.Arrays class.

  Write a program to calculate the probabilities of collisions

Write a program to calculate the probabilities of collisions for the following: You are asked to write a program to store information for customers for a small local business.

  Automated code coverage and cyclomatic complexity analyses

Automated code coverage and cyclomatic complexity analyses -

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd