Assignment - Graphical Sorting Assignment
Using Applets, you are going to animate the sorting techniques we have learned in class (Bubble, Selection, Shaker, Insertion. NOT Bin Sort). This diagram is missing many of the required features, but it gives you an idea of what is required.
Graphics g = getGraphics();set the x position to 50
for all of the values in the array
draw a rectangle that starts at x, 50 and goes the length of that array element and down 10 pixels.
increase x by 10 pixels (width of the bar) and 2 pixels (space between).
g.setColor(Color.white);g.fillRect(25,25,500,500);//and reset colour to something useful
for(int i=0; i<5000000; i++); //Waste time
This code does nothing and slows down the program so that we can see it sorthing.
public void reset()
{a[0]=1;
a[1]=56; etc...... for all 20 elements.
Call the reset method in the action method.
import
java.awt.*;
import java.applet.*;
public class SortAnimator extends Applet
{
Button select, bubble, insert;
int size = 10;
int a [];
Button reset;
public void init ()
{
select = new Button ("selection sort");
add (select);
bubble = new Button ("bubble sort");
add (bubble);
insert = new Button ("insertion sort");
add (insert);
reset = new Button ("Reset array");
add (reset);
}
public boolean action (Event e, Object o)
{
if (e.target == select)
{
}
else if (e.target == bubble)
{
}
else if (e.target == insert)
{
}
else if (e.target == reset)
{
}
return true;
}
public void paint (Graphics g)
{
g.setColor (Color.red);
}
}
Graphical Sorting Assignment Rubric Name: ________________
Content (Application) /22
| User-friendly /5 |
Instructions to the user. Outlines characteristics of each sort. |
Basic Instructions to user. Titles. Nicely labeled buttons. |
Very basic instructions to user. Needs titles. Spelling and grammar should be checked. |
Needs titles and instructions to users. Spelling and grammar should be checked. |
| Print array& GUI /9 |
Border, titles, animation, etc. to make the screen look better. Fonts, colour, panels used effectively. |
Bars printed to represent the array. Bars coloured. Fonts, colour, panels used. |
Basic Bars printed on the screen. |
Problems with outputting. |
| Code /8 |
Initializes array in a function, All of bubble sort, shaker sort, insert sort, selection sort. Something extra. |
Doesn’t do one or more of level 4. Reset button works. |
One missing of selection, insert, shaker and bubble. |
Does not compile. |
Style (Communication) /8
| Comment /4 |
3 title comments. Excellent spelling and grammar. Comments before sections. |
3 title comments. Comments before most sections of code. |
3 title comments. Some comments. |
None. |
| Space /2 |
White space before major sections of code. Code is tabbed well. |
Some white space/tabbing errors. |
Many white space/tabbing errors. |
Code is extremely difficult to read. |
| Pre Post /2 |
Very clear pre and post conditions on all functions. Array’s condition and size are always clearly stated. |
Pre and post conditions on all functions. |
Pre and post conditions on many functions. |
Few to none pre and post conditions. |