Question
Attached is a photo of a HW assignment that I am currently stuck on. I would really appreciate some help with this. You must read
Attached is a photo of a HW assignment that I am currently stuck on. I would really appreciate some help with this. You must read from two separate text files to complete this assignment, one of them is StateAccidents.txt which is formatted like so:
STATE VE_TOTAL PERSONS FATALS 1 1 1 1 1 3 4 2
1 2 5 1 1 2 2 1 1 2 5 1 1 1 2 1 1 2 2 1 1 2 2 1 1 2 7 1
but several thousand more lines of that.
the other txt file is StateCode.txt which is formatted like this:
code state 1 Alabama 2 Alaska 4 Arizona 5 Arkansas 6 California 8 Colorado 9 Connecticut 10 Delaware 11 District of Columbia 12 Florida 13 Georgia 15 Hawaii 16 Idaho 17 Illinois 18 Indiana 19 Iowa 20 Kansas 21 Kentucky 22 Louisiana 23 Maine 24 Maryland 25 Massachusetts 26 Michigan 27 Minnesota 28 Mississippi 29 Missouri 30 Montana 31 Nebraska 32 Nevada 33 New Hampshire 34 New Jersey 35 New Mexico 36 New York 37 North Carolina 38 North Dakota 39 Ohio 40 Oklahoma 41 Oregon 42 Pennsylvania 43 Puerto Rico 44 Rhode Island 45 South Carolina 46 South Dakota 47 Tennessee 48 Texas 49 Utah 50 Vermont 52 Virgin Islands 51 Virginia 53 Washington 54 West Virginia 55 Wisconsin 56 Wyoming
If you need any other information please let me know so I can provide it. I am almost done with my code, but I am running into a problem that I can't fix, so I'd like to look at your example to compare and see where I can improve my own code. Thank you!
The attached files are the data for traffic accidents happened at different states. The Accidents.txt contains record for each accident, including at which state it happened (denoted by the state ID), the number of vehicles involved in that accident, number of persons involved in that accident, and the number of fatality (i.e., the number of people who died) in that accident. The State Code.txt contains the ID (code) and name for each state. Our job is to print out the total number of accidents happened at each state. The project should meet the following requirements: Have a StateAccident class which implements the following UML as minimum: StateAccident - statelD: int - stateName: String - accidentCount: int + StateAccident (stateld: int, stateName: String) + ... Other Constructors as needed + ... setters and getters for all fields + incrementAccidentCount(): void + toString(): String + any other methods as needed Have an Outer Main class which drives the analysis. It should a) create an ArrayList of the type StateAccident, b) read the state id and name from StateCode.txt, create objects for each state, and add those objects into the ArrayList, c) read data from Accidents.txt and count how many accidents happened at each state. Update the accident Count for the State Accident objects in the ArrayList. d) at the end output the stats by iterating over the ArrayList and call the toString() method for each objects. To verify, the result is shown below. Each line in the output should be a string returned by the toString() method. Look into the String.format() method if you want to format a string nicely. 1010 1 2 4 5 Alabama Alaska Arizona Arkansas 948 584Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started