CIS 180: Object-Oriented
Programming
Programming
Project #6
Sorting
Algorithms
Due by Dec.
12th, 2003
Objectives
The objectives of this homework are:
To practice GUI based IO
To practice passing arrays
as parameters.
To practice sorting algorithms
and think about their efficiency
Problem Statement
Write a GUI-based application allowing the user to enter
a set of integers and choose a sorting algorithm for sorting them. The application
sorts the numbers from smallest to the largest using the algorithm selected
by the user. The sorted numbers are displayed. In addition to sorting the
numbers the application counts and displays the number of swaps for the selected
algorithm, where a ÒswapÓ means switching two elements of an array.
HINT: Reuse some of the design and code from Homework
#5 !
Constraints
- Numbers are whole numbers.
- The count of numbers is not known in
advance. You can not ask the user for the count of numbers he/she is
planning to enter.
- Numbers are sorted in increasing order
only.
- Numbers are entered by the user in
one sequence where numbers are separated by spaces. They should be displayed
in the same format.
- User can clear the display area through
a menu selection
- Two algorithms offered to the user
are: Bubble Sort and Selection Sort
- The algorithm is chosen by the user
through a menu selection.
- The sorting algorithms are implemented
as separate methods taking as a parameter an array of integers and returning
the number of swaps performed during the sort of this array.
Interface
- Use TextArea components numbers , sortedNumbers for entering and display of the numbers
- Use JMenuBar with one JMenu. The JMenu should contain three JMenuItems bubble sort , selection sort,
reset. The reset JMenuItem should be the last on the list and separated
from the others by a separator HINT: use method addSeparator
( )
- Selection of the algorithm through
the menu triggers its execution.
- Use TextField component swapCount to display the count of swaps during the
execution of a selected algorithm.
Steps to take
- Write the "shell for a frame-based
application"
- Test the application.
- Lay-out a design for GUI
- Implement the GUI in your application
- Test the application with the new GUI
- Implement the sorting algorithms
- Design the event handling
- Implement event handlers
- "Wire" the handlers to the components
- Test the entire application to make
sure it runs correctly
- Perform the following tests of both
algorithms:
- Enter 10 numbers sorted from the
largest to the smallest
- Enter 10 numbers sorted from the
smallest to the largest
- Enter 10 numbers sorted from smallest
to the largest with exception of two numbers that are ÒmisplacedÓ (
not in the correct order )
- Enter 10 numbers in a random order
- Analyze the results of your testing
and draw the conclusions
What to turn in
When your assignment is complete, add some comments
to the beginning of the java source code explaining any problems you encountered
in completing the assignment and describing any bugs in your solution. Undocumented
bugs are worse than documented bugs. If you have undocumented bugs we will
assume that you did an inadequate job of testing your code, and you will
lose additional points.
Prepare a report showing the data entered, algorithm, and swap
count for all the tests. Provide the results of your analysis in form of
your observations, conclusions and possibly some suggestions of other tests
that may prove your point. Course instructor will provide you with information
how to submit this portion of your homework.
To submit your homework, follow the link from the homework
page to the homework submission form.
There will be a 10% penalty for assignments received
after the due date. Assignments will not be accepted more than one week past
the due
date.