CIS 180: Object-Oriented Programming
Programming Project #5
Sorting & Arrays
Due by Dec 2, 2003
Objectives
The objectives of this homework are:
To practice Input/Output of data to/from arrays
To practice loops in connection with arrays
To use sorting algorithms when working with arrays
Problem Statement
Write an applet allowing the user to enter a set of
integers and choose an order of sorting them. The applet should sort the
numbers and display them.
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.
- User can request increasing or decreasing
order.
- 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 and
start the process again
Interface
- Use TextArea components numbers
, sortedNumbers for entering and
display of the numbers.
- Use Button components up, down to choose the order of numbers to be
displayed.
- Use Button clear to clear the TextArea numbers and sortedNumbers.
Steps to take
- Lay-out a design for the Graphical
User Interface (GUI).
- Design the way you are going to store
the numbers. HINT: use
an array. What a helpful hint!
- Figure out how you are going to find
the count of numbers entered. HINT: get the String from TextArea numbers
and use StringTokenizer
to find out how many numbers it contains. This information will be critical
in allocating an array of the right size.
- Figure out how you are going to get
the numbers. HINT: use
StringTokenizer to break the String from TextArea numbers to String objects representing individual
numbers. Convert each of these String objects to an integer and store
it. Check if class Integer can be of some help to you in this task.
- Design the event handling required
to provide the above functionality. HINT: think about event, its source, its handler,
and the actions to be taken when the event occurs. Does the user's
decision about order of numbers display impact the order of sorting?
- Write a "shell" of an applet.
- Implement the GUI.
- Test the applet with the GUI.
- Implement the reading and storing of
the numbers from TextArea numbers.
- Implement the sorting. HINT: you can use any algorithm you like
as long as it does the job
- Implement the event handling causing
the display of the numbers in the requested order in the TextArea sortedNumbers.
- Implement the event handling for clearing
the TextArea components when requested by the user by pressing the clear
Button.
- Test the entire program.
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.
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.
You're done.
Great work!