Thursday February 17, 2005
Due Wednesday 2/23/2005
The homework has several parts. To avoid conflicts, you
must develop each program in a separate directory (Hw4I, Hw4II and Hw4III, all in Hw4).
Using the GUI from the previous homework, develop a full program for sorting an array of integers using both Selection and
Insertion Sort, using the algorithms and the implementation sketches
developed in class today.
Use Variations on a Cookie Jar for model and
The Cookie Jar abstract data type.
Design and test a new class called CookieJar, with the following specifications:
Test your class by including it in a very simple applet, where the information in the jar is illustrated simply by
priinting on the Java console or on the screen.
- Class variables: number of cookies (integer).
- Constructor: empty jar and constructor with a given number of cookies to start with.
- Methods: add, count. Testing and visualization methods: Print, Draw.
- Modify the CookieJar class to include new functions for
removing cookies and testing the status of a cookie jar:
- delete: takes in a number k, and removes k cookies from the jar.
- IsEmpty: returns true or false, depending on whether the
cookie jar is empty or not.
- IsFull: returns true or false, depending on whether the jar
is full or not. To do this part, you will have to add a new
private variable maxNum in the description of the
JarType. This variable will have to be initialized in the
constructor, and will give the maximum capacity of the jar.
- Add a graphical user interface to Part II for visualizing the cookie jar. You probably will use a filled circle to
draw a cookie, and put them all in a row. The drawing must be done via the Draw method of the CookieJar class.
- For bonus points, draw each cookie as a fancier object (e.g like a little cat or mouse with eyes and whiskers)
and arrange them vertically.