starting foreach CS230: Data Structures

CS230

 

Goals:

Practice with:

  • Working with Java's LinkedLists
  • Reading from and Writing to files, employing and handling IOExceptions
 

Exercise: Evictions Using LinkedLists

In the exercise you will write an application to read town data, including populations and number of evictions, to determine towns with high evictions. Results will be written in a file. In the application you will use a Linked Lists as the Data Structure to hold the Town objects.

In the downloaded material you will find:

  1. Town.java: a complete and working version of the Town class. This code should not be modified! Please look at this code, in particular the setFlag() method. Notice that it returns a boolean value.
  2. EvictionsList.java: it contains a bit of starting code; you need to complete the implementation of this class. See further down for more information on what methods to define.
  3. smallEvictionsData.txt: a short file that contains only a few lines of input data, one town per line. The formatting of this file will obviously affect your code that reads from the input file. Notice that each town's data are separated by tabs, not spaces. Also, this file will be very useful as you start testing your program, since you can easily (by eye) verify the correctness of the produced results.
  4. completeEvictionsData.txt: an input file that contains real data of some 25,069 towns from 2016. The formatting of this input file is exactly the same as the formatting of the smallEvictionsData.txt.

What to do:

  1. Download the starting material for this exercise, in the folder evictionsList_starter_code. Rename the folder to evictionsList_yourUserName(s).
  2. Study the code give to you in both the (complete) Town.java as well as in the (incomplete) EvictionsList.java files.
  3. Finish the implementation in the EvictionsList.java class. In particular, write the following methods:

    1. constructor of EvictionsList, which takes the name of the file with the input data
    2. readFromFile(), to read the data from the file into the LinkedList of Town objects
    3. flagTowns(), to set the flag on each town to either true or false
    4. writeToFile(), to write the results into an output file, the name of which is coming as an input to this method. Please, write to this file exactly the information the (given) toString() prints on the screen.
    5. main() method: add some testing code (see more in the submission section). Notice that the input file (data) should only be read once in the main() method!
  4. As always, debug and test your code incrementally and carefully. You can use copious printing statements during these phases. You are also encouraged to use the BlueJ's debugger. This program offers itself for that!

  5. Add careful and high quality documentation to your program, including javadoc.
Note on File reading:

We suggest that you use the tab (\t), newline (\n), and carriage-return (\r) as delimiters to identify tokens when reading from those files, not just a space, so that you can read two-word town names, like "San Francisco", as a town's name. To do so, after you instantiate the Scanner variable scan, use this command to set the delimiters:

scan.useDelimiter("\t|\\r|\\n");

Requirements:

You are asked to use java's LinkedList in your code. In particular use the following LinkedList methods only:

  1. constructor of a LinkedList of Towns
  2. add()
  3. get()
  4. size()

If you think in this exercise you need more methods from the LinkedList ATD, please talk to one of us!

What to submit

In Gradescope submit one .zip file that contains the following:

  1. the EvictionsList.java file
  2. your output files: eight (8) .txt files with the results of running your program on the two given input files, for each of the four thresholds.
  3. a file, named results.txt: a simple text file where you type the results (number of towns flagged) of running your program on each of the two input files with the following threshold values:
    1. threshold is 0.08%
    2. threshold is 0.5%
    3. threshold is 0.8%, and
    4. threshold is 8%.

Present your results in a nice and easy-to-read way. Consider using a 2-dimensional table format for this. Finally, add a sentence or two, to explain whether these results are logical.