We are going to continue our problem-solving education by writing a program that processes a file and calculates statistics. Operating with data files is a very powerful and useful tool. TextIO makes reading in from files very easy. I recommend you use TextIO instead of java.util.Scanner.
We will also get more practice using Eclipse to make our programming life easier.
This is where we will put all our classes for homework 04.
Write a program that will compute and print the total visitors from all the countries together and their average spending.
The data file contains visitor information about visitors to Hawaii from various countries. Each line of the file contains a country name, followed by a colon ‘:’ followed by the number of visitors for that country, followed by a colon ‘:’, followed by the dollars spent by the visitors. The number of visitors is a number of type int. The dollars spent is a number of type double. However, for some countries, no data was available. In these lines, the data is replaced by a comment explaining why the data is missing. For example, several lines from the file might look like:
Canada: 135132: 140020521.00
Bulgaria: no report received
Mexico: 200123: 98298734.12
The program should also report the number of countries for which data was not available. The name of the file is “visitors.dat”.
You can download an example visitors.dat file to test your code. You should create your own files for testing.
Do you understand what the program needs to do?
Use the steps from H02 to create your Java program and boilerplate code.
“What are the steps needed to solve this problem?” Write them down as comments in the main method. Once you have the steps start refining them till you can write Java code.
Criterion | Excellent (100%) | Satisfactory (75%) | Borderline (50%) | Unsatisfactory (25%) | Poor (0) |
---|---|---|---|---|---|
Adherence to standards - 2 points Does it conform to standards in every detail? |
No errors. | Minor details of the assignment are violated, or poor choices are made where the assignment is unclear. | Significant details of the assignment or the underlying program intent are violated, but the program still fulfills essential functions. | Significant details of the assignment or the underlying program intent are violated, but the program still fulfills some essential functions. | Misses the point of the assignment. |
Breakdown (modular design) - 1 point Does it demonstrate good modular design? |
No errors. | 1-3 minor errors. | > 3 minor errors OR 1 major error. | 2 major errors | > 2 major error. |
Correctness of code - 5 points Does it work? Does it pass JUnit? |
Passes all tests. | Works for typical input, may fail for minor special cases. | Fails for typical input, for a minor reason. | Fails for typical input, for a major reason. | No. |
Documentation, and style - 2 points Is it clear and maintainable? Does it pass CheckStyle? |
No errors. | 1-3 minor errors. | > 3 minor errors OR 1 major error. | 2 major errors | > 2 major error. |
The assignment is due on Friday, September 24th at 11:55pm. You may turn it in early.
Conduct a personal review of your code before turning it in. Does your code follow the Java Coding Standard?
Test your code.
Export your ICS111-workspace project by choosing File -> Export. Name the zip file H04.zip.
Sign into Laulima, then navigate to the ICS111 site. In the left hand side of the site, there is an Assignments tab/link. Click on it and view all of the posted assignments. Select the assignment that you want to turn in and attach your H04.zip file and accept the honor pledge to submit the assignment.