CS100J     Spring 2003     Assignment 7    Maintaining Bowling Scores III (statistics)

Submit your solution on CMS by the deadline: 23:59, Tuesday, 25 November

You may work in groups of 2. But PLEASE form your group well before you submit!!!!

DO NOT WAIT UNTIL THE LAST MINUTE TO DO THIS ASSIGNMENT. Doing part of it every day or every other day will make it easier and more pleasant. It may seem like a large and complex project, but if you focus one one part at a time, putting the rest completely out of your mind, it will be quite manageable.

Introduction

This is the third in a series of three assignments that deal with maintaining duckpin bowling scores.

You can see how a program is broken up logically into pieces, each dealing with a different aspect. Classes are used to organize this information in a suitable manner.

Bowling

See the assignment 5 handout for a description of the game.

Classes Frame and Game

You wrote these classes in the previous assignments. You can use your own classes Frame and Game or ours while writing and testing the program. However, when we test your program, we will be using our classes Frame and Game, not yours.

Download a jar file that contains the application for this game as a jar file and this file of bowling games. Run the application to see what your final program will do. Note that the GUI contains an "output area", where the list of games is displayed. Your program will place the list of games in this output area.

Here are four classes that you should download: Duckpins, JLiveWindow, Methods, and IO. JLiveWindow provides the GUI; it is an instance of class Frame. Class Methods contains some static methods. Class Duckpins contains the main program, as well as method buttonPressed, which is called whenever the ready button in the GUI is pressed. Class IO is one that we used in lecture to demonstrate reading a file. You don't have to change it at all. In addition, here are our classes Frame and Game and a file of games to test with.

You can get all of these files in this zipped file: skeleton.zip.

Before you begin, scan through this document to get a basic understanding of this project and spend some time reading all classes Duckpins, Methods, and IO.

As usual, we give below a series of steps that you should take in carrying out this assignment. We urge you to carry them out in the order given. Further, don't go on to the next step until you are completely satisfied that the one you are doing is correct. Test thoroughly, using enough test cases to give you absolute confidence in what you programmed.

You will be storing a collection of games in an instance of class Vector. We discussed class Vector in a recitation several moons ago. Lesson page 5-5 of ProgramLive has all the information you need on Vectors.

Step 0. Overall view of the program. Take a look at the beginning of class Duckpins. There is a Vector games and a Vector working. Vector games contains the last file of games that was read in. Vector working is the set of games that are currently being processed and displayed. Thus, whenever a file of games is read into games, games is COPIED into working.

Now take a look at method Duckpins.buttonPressed. It is called whenever the ready button of the GUI is clicked. We have left the overall structure of this method untouched; you have to fill in some of its commands. You can see that it looks at the first int field of the GUI to determine what command to execute and then executes that command. It is a simple structure.

We have completed the instructions for the case that the int field of the GUI contains 0, so that you can see how simply these can be written (most of them are simpler). But you have to write procedure readGames, function Methods.copy, and method output. We now discuss each command in turn. By "command 0", we mean the code that is executed when the GUI int field contains 0 and the ready button is pressed. Similarly for the others.

Command 0. Getting the command (with input field 0) working. The first thing to do is to write some methods. See below.

Command 0. Method readGames. The first thing to do is to write method readGames of class Duckpins. We have written some of it for you, because it requires things that you don't know about yet, having to do with Exceptions and catching them. As you can see, we have written the call on a method in class IO to get the name of a file from the user, using a dialog window.

You have to write the code that reads the lines from this file and makes up Vector games from them. A full explanation appears as a comment in this class. You have to know what methods you can use on BufferedReader. We discussed this in class. Sec. 5.7 and lesson page 5-7 of the CD contain information on reading from files. Activity 5 shows you how to read the lines of a file.

You should test this method carefully before proceeding. One way to do this is to write a loop that prints the games (from Vector games), using the toString method of each game.

Command 0. Method Methods.copy(Vector). Next, write method Methods.copy(Vector). Test it before proceeding to the next step.

Command 0. Method output. Write method output of class Duckpins. Two methods have been already written to help you here: clearOutput and appendOutputln. Read their specifications. Note that the specification of method output says that there should be two lines per game, and it states precisely what the values of these lines should be.

Command 0. Running the program. Once you have written method output, do this. (0) Start the program, by executing the call Duckpins.main(null); (1) Type 0 in the int field of the GUI. (2) Click the ready button. (3) In the dialog window that pops up, navigate to and select file scores.txt. (4) See the list of games displayed in the output field of the GUI. If it doesn't, then you have errors in your progam.

Command 1. Clear the output area and put the working set into it. We give you the code for it. It should work, provided you have written method output correctly.

Command 2. Sort the working set by total score. You may do this any way you wish, but don't put the whole code for sorting in this command. Instead, write a static procedure to sort and call this procedure.

In class Methods, we have stubbed in two methods that will help you here: selectionsort and min. One way to fill them in is to get the code for these procedures from ProgramLive and then change them to (1) use a Vector instead of an array and (2) make them sort (or find the minimum) depending on parameter kind or whichMin.

If you feel more at ease writing four different min procedures and four different selection sort procedures, then do so (see Commands 3, 4, 5).

Command 3. Sort the working set in descending order of total score. See the instructions for command 2.

Command 4. Sort the working set by person's name. See the instructions for command 2.

Command 5. Sort the working set in reverse alphabetical order of the person's name. See the instructions for command 2.

Command 6. Append statistics of the working set. You have to write method outputStatistics.

Command 7. Set the working set to all the games read in earlier. This should be very easy to write, since you have already written methods that will help do the job.

Command 8. Remove from the working set the games of the person whose name is in the first String field. This will require you to obtain the value that is in the String field of the GUI. Look at the comment of method buttonPressed for information on doing this. Be sure to trim preceding and following blanks from the name. You should also complete the two-parameter method Methods.copy(Vector, String). Then, place a suitable call to this method in the code that handles command 8.

Command 9. Remove from he working set the games with scores of < 200. Complete the two-parameter method Methods.copy(Vector, int). Then, place a suitable call to this method in the code that handles command 7.

Precaution. We remind you that every command except 1 and 6 should end by clearing the output area and placing the working set in it.

Submit the assignment. Submit your solution on CMS by the deadline, which is 23:59, Tuesday, 25 November. We need only files Duckpins.java and Methods.java.