Advanced Programming - CS239
LAB 19: Sorting
algorithms – This lab will give you a preview of Tuesday’s lecture.
Getting
Ready: Before going any further you should:
- Make a directory on
your N: drive for this lab.
(Note: You will need to use this class in future labs.)
- Set up your
development environment.
Part I: In this
part, you will build your Driver program to read a series of values from a file
and create an array of those values to be used in Part II. (Review)
- You will need to set up a Scanner to read double values from a
file. These values may appear on
the same line separated by whitespace or may be on separate lines. You will not know in advance how many
values you will have. Don’t forget,
if a value is encountered that is not a double you must deal with that
situation and not abort the program.
Appropriate error messages should be provided. (You may use prior labs as a base for
this step)
- Write a VERY SHORT program to test the toArray method in the ArrayList class. Call me over to show it to me when you
have it working. You MAY hard code it (i.e. you don’t have tomake it general.
- As you read in each appropriate value, you should store it in an
ArrayList structure.
- When the file is exhausted, convert the ArrayList into an array of double. (See ArrayList methods).
- Print the values in the array, one per line.
Part II: In
this part, you will create a method to sort your array from Part I.
- Create a new class, Sorts, which will hold your new sort
method.
- Create a method sortArray which will have an array of double as a
parameter and returns nothing. It
should sort the Array into ascending order by value. If two values are the same, they should
be stored in contiguous locations in the array.
- Be sure to document your method.
Part III: Test your method
- Return to your
Driver program. Add code at the end
of main to call the sort method passing in the array.
- After return from
the sort, print the array as you did in step 4.
Part IV: Turn in a printout of your sortArray method
Part V: Turn in a floppy
with your lab
on it (NOTE: I have floppies if you don’t have one with you.