Computer Science 15-100 (Sections T & U), Fall 2007
Homework 9
Due: Fri 7-Dec-2007 at 8:30am (email copy) and at recitation (physical
copy)
- Be sure to include your name, your Andrew ID, and your section (T or
U) clearly on the top of your assignment (both written and electronic)!
- Your submission (electronic and physical) will include these files:
- Hw9Q2_1.java
- Hw9Q2_2.java
- Hw9Q3.java
- Hw9Q4.java
- Hw9Q5.java
- Read L&L Chapters 8 (8.1 - 8.5) and 9 (9.1 - 9.6) and study the relevant Key Concepts and
the Self-Review Questions and Answers. Do not submit these.
- Do the following Programming Problems from L&L:
- Any one of these: PP 8.2, 8.3, 8.4, 8.5, 8.11, 8.12, 8.13
- Bonus [optional]: PP 8.9
- Here you will make a simple animation. To do this, start from
BasicGraphicsWithTimer.java. This is just like BasicGraphics.java, but
it includes the code we need for simple animations. In particular, it
has a method called "onTimer" that will be called at regular intervals (if
you look closely at the code, you will see how you can control how
frequently this method is called). To animate a graphical object, just
make some of its properties into instance variables, and then change those
instance variables inside the onTimer method. The included example
shows how to animate a yellow circle so it moves across the screen
repeatedly. Study this example and be sure you understand how it
works. Then, create the following animation:
- PP 9.6 (but do it for bubblesort instead of selection sort, and do this using the animation technique you just learned in
the previous exercise). Basically, you are implementing your own
simplified version of xSortLab.
- BONUS [optional -- worth 20 pts]: Generalize PP 9.6 so that it uses classes and inheritance to work for
several other sort algorithms (bubblesort, insertion sort, and selection
sort). To do this, create a class
named SortAnimator that does the main animation. This class's
constructor should take a SortAlgorithm instance. SortAlgorithm should
be an abstract class, where a SortAlgorithm should have a method
setArray(int[] array), that sets the array to be sorted, and then a method
step(). The step method should return an instance of SortStep, which
describes what the sort array will do in the next step as it sorts the given
array. A "step" may be something like comparing two elements, swapping
two elements, etc. The SortAnimator will create a SortAlgorithm
instance, give it a random array, and then repeatedly call its step method
and display the result. Naturally, BubbleSort, SelectionSort, and
InsertionSort are all subclasses of SortAlgorithm. The rest is up to
you.... :-)
Carpe diem!