Go to the CodingBat site,
and write code to solve the
lab5 folder to your Desktop. Rename it to include the names of the two
Town.java given code. Finish up the implementation of this class.
In particular do the following:
toString()method to return a reasonable String representation of a Town object.
compareTo()method to implement the
ComparableInterface. Town comparison, for our purposes, should happen based on the eviction rates: a Town with larger eviction rate than an other one is considered "larger".
equals()method. Two towns are equal when they have the same name and the same state.
main()method, with some code to test your work
[end of PRELAB]
Relevant downloaded files:
Write a program, from scratch, that will read in a file of town data regarding evictions in a certain year, and decide which of those towns should be on the watch because eviction data are raising concerns. It will write these town-under-watch to a file.
A town is considered to be "on-the-watch" if its eviction rate is greater than some threshold. This threshold is the same for all Towns, obviously. Provide means of setting it to different values.
Input is coming from the file named
evictionData.txt. Open the file in a text editor,
and examine its formatting. Notice that the first line of the file contains headers (no data.)
The program should do the following:
java classes to importto this class?
instance variablesto include in this class?
How do you expect your program to behave if the input and/or output file does not exist? How can you test your answer to the previous question? Go ahead, do so!
How about if the data itself is malformed? For example, what happens if one town's population or/and evictions number, or/and poverty rate is not a proper number (int or double)? Temporarily edit the input data file so that it contains some malformed data to test your hypothesis.
catchstatements and print an informative message about what went wrong in the execution of this program. Be sure to test each of the exceptions as well. Of course, feel free to add more data to the input file, or modify the existing ones for your testing needs. If one record is problematic, how is your program dealing with the records that follow after it?
This is getting really interesting, right? Think about how you can modify your program so that when an invalid town record is encountered, the whole record is ignored, but the reading continues with the next student record. Can you arrange so that the problematic record is just skipped, a message is presented, and the program continues with the next record?