CS 112b
Spring 2005
Ileana Streinu
Homework 3
Thursday February 10, 2005
Due Wednesday Feb. 16, 2005
by midnight
Outline
Your task is to write a Java applet similar in behaviour to the
Selection Sort model shown in class on Thursday. The implementation
must obey certain design techniques:
- The array of numbers to be sorted is a class variable in your main applet.
- The Sorting algorithm will be a method in the myApplet class.
- Selection Sort will be implemented using additional functions: FindMax, to find the maximum of an array,
and Swap, to swap to elements in an array, given by their positions.
- The GUI must be similar to, but not necessarily as sophisticated at the one in the
model applet. More precisely, you will still enter the data by using mouse click-and-drag.
The extent of the dragging will be read-off as a value for the current element to enter in the array of numbers. But
you do not have to represent the squares at the location where they have been created by the user via mouse clicks. Instead,
it suffices to draw only the current square, then as soon as the mouse is released, draw it together with the rest of the array.
- You must implement a Print method in your applet, which prints the contents of the array on the Java console. This method
must be used extensively for debugging.
Details
The design of the applet must proceed in stages - do not attempt to do everything at once.
- The design of the applet class should proceed by stepwise refinement.
Implement first the GUI, and later add the sorting methods. Additional
methods can be added as the development of the applet progresses.
- To be (more or less) completed by Tuesday:
- Basic GUI: buttons, mouse clicks which insert elements in the array, printing and drawing of the array on the applet.
- Then, after Tuesday's class, add methods for:
- Test them individually (by adding extra buttons to your applet, for instance).
Extra Credit
Design a user interface similar to the one in the model applet, where
the squares are drawn where they are clicked on, and then rearranged in a linear vector only when the Done button is
clicked.
Ileana Streinu