CompSci 6- Classwork 8 - Feb 9, 2010
10 pts

Today's classwork focuses on implementing computing the mode of a list of numbers.

You will work with your group, but each of you should also use a laptop and solve all the problems. You should discuss problems with your group and help each other debug.

Snarf the classwork/08_files project. The source directory is also linked here.

Problems

  1. The ClassScores class includes a method called getScanner. This method opens up a file chooser and returns a Scanner to the selected file. Write the necessary code in your main method to construct a ClassScores object and call the getScanner method to bind the selected file to a Scanner named in.

  2. When working with files, you often need to read in the data and check that it matches your expectations. Complete the method readAndPrintFile, to print each token from the file - one per line.

    For example, if given the following file excerpt of library holdings from the data directory of the natural prestidigitation assignment:

    (* Library holdings (# of books in each library), *) (* collected by Christian Ayotte. *) (* Labels not available. *) 12201 600778 14926 37863 ...
    your program should print:
    (* Library holdings (# of books in each library), *) (* collected by Christian Ayotte. *) (* Labels not available. *) 12201 600778 14926 37863 ...
  3. The mode of a list of numbers is the most commonly occuring number(s). For example, if you have the following numbers, [88, 70, 65, 70, 88], the modes are 70 and 88 because they occur twice, while 65 ocurs once. The following problems ask you to complete methods in the ClassScores class that you snarfed.

    1. The ClassScores class has two different findMode methods. Why? How does Java distinguish the two methods? Write your answer in your README.

    2. Complete the findMode(int[]) method. Test using:
      1. the array example in the main method
      2. the APT page.

    3. Complete the findMode(Scanner) method. Test using:
      • Files in the data directory.
      • Files that you create

Submitting

Submit your README, ClassScores.java, and any test data files via Ambient using assignment name ClassworkFeb09.