CS 210 Programming Assignment 1 Spring 2006
Due Tuesday, Feb. 7 and
Purpose
This assignment aims to help you:
Before working on this assignment, you should read chapters 3 and 4 in the text. You can skip Sections 4.5.3, 4.8, and 4.9. Also, read and follow the Java setup directions for your home PC, linked from the class web page at the end, as "Install at Home Hints."
Description
In this assignment, you are going to implement an extension to the qualifying exam program. See $cs210/pa1 for a solution to work from. This extension allows us to choose different algorithms to maintain a BinCollection. The qualifying assignment has a SimpleBinCollection class with an algorithm for adding boxes to bins that puts a box in the first bin with enough space. In addition to that algorithm, you will implement a WorstFitBinCollection class that has an add method that adds a box to the bin with the largest available space provided that the box fits in the space. Along the way, you’ll implement:
Design
You should start with the class design of Qualifying Assignment. The modifications here are:
1. In the qualifying exam setup, we used a boolean return value to
indicate a too-large Box. Implement an InsufficientSpaceException and use exceptions to signal a
too-large Box instead.
2. Set up the BinCollection interface. The interface has the following methods similar to the methods of SimpleBinCollection class of the Qualifying Assignment
public void addBox(Box
b) throws InsufficientSpaceException
public int size()
3. Design the WorstFitBinCollection class. This class must implement the BinCollection interface. As described above, the add method should behave as follows:
4. Create an abstract AbstractBinCollection class. This class should implement the BinCollection interface and contain common implementations shared by the concrete BinCollection classes (SimpleBinCollection and WorstFitBinCollection). Make the concrete classes sub classes of this class. Make sure that the shared implementations are in the AbstractBinCollection class, not the concrete classes.
5. Create a BinCollectionTester class that contains the following method, called from main, itself still in BinCollectionDriver, for instances of the two kinds of BinCollection:
public static int runTest( int[] sizes, BinCollection bins ) – tests the behavior of the given BinCollection by adding boxes who heights are described, in order, by the values in the sizes array, then returns the number of bins in the resulting BinCollection.
Simplify main accordingly, and end up with a program that outputs "SimpleBinCollection results", then the report of boxes in bins as on the qualifying exam, then "WorstFitBinCollection results", and then the same sort of report on its results.
first.txt: progress report on pa1, due Tueday noon, Feb. 8
1. Have you successfully set up Java on your development system? If not, what happened? In either case, give the output for the tests listed at the end of the "Install At Home Hints" page.
2. What IDE are you using? Any problems?
3. Have you successfully built and run the qualifying exam program on your own system using the IDE? If not, what problems are you having?
4. Have you successfully built and run the qualifying exam program using command line tools? If not, what problems are you having?
5. Have you converted Bin.java to using the exception? Any problems?
memo.txt (due with rest of files on Feb. 13)
In the file memo.txt, answer the following questions,
in one to three pages (60-180 lines) of text.
Use complete sentences, as you would for an English class
1. What problems did you encounter and how did you solve
them?
What Java development environment (IDE) did you use? Any problems with it?
Did you use the textbook examples to help you? Which ones?
Did you access any information on the Web during this
work? Where?
Did you discuss this material with other people? Who?
What?
2. We switched from returning an error indication to causing an exception for a too-large Box. Was this an improvement? Discuss.
3. Which BinCollection implementation resulted in using fewer bins? Why do you think this is true?
4. Explain the role of the BinCollection interface and the AbstractBinCollection class. What is the advantage of using these techniques?
Turn In
Use the turnin system to submit your files. Before the due date, submit the following files to the pa1 folder of your turnin system account:
First Delivery, due Tuesday noon, Feb. 7
Main Delivery, due Monday noon, Feb. 13
memo.txt (plain textfile)We will run a program that compiles and tests the Java code, and collect all files for the grader. It is your responsibility to make sure those files are present, that their names are spelled correctly (e.g. we will not find Memo.txt or memo.TXT) and that the files are turned in for the proper assignment folder.