Due: Saturday, 15 April 2000
Design, run, and test a Java project which sorts an array of Movie objects by means of a recursive merge sort. This algorithm has been (or will soon be) discussed in class. For the sake of simplicity, assume that a Movie object consists of a string representing the name of a film. In addition to a Movie class, create a class called MovieGroup. An object in the MovieGroup class consists of a group of Movie objects, indexed by an array, and an integer representing the number of Movie objects in the group. For example, Comedy may refer to the object defined by {[M0, M1, M2], 3} where M0 is defined by "Groundhog Day", M1 is defined by "Hairspray", and M2 is defined by "Truman Show", and the integer 3 (representing the number of movies in the group). Your main method in the MergeDemo class will instantiate a MovieGroup object, entered by the user. It will then invoke the mergeSort() method (in the MovieGroup class). Finally, the titles of the films will be printed in lexicographic order, using a writeOutput() method.
In your MovieGroup class you will need the following three methods:
void sort() // an instance method which is called by a MovieGroup object
void static mergeSort (Movie[] films, int firstIndex, int lastIndex) // a static method used in the sort method
void static merge (Movie[] films, int firstIndex, int middleIndex, int lastIndex) // a static method used in the mergeSort method
Sample dialogue:
Please enter a sequence of movie titles. To end, enter *.
Dead
Ringers
Nightmare
On Elm Street
The
Cube
War
Of The Worlds
Repulsion
Master
Of Illusions
In
The Mouth Of Madness
Prince
Of Darkness
HellBound
HellRaiser
Dead
Of Night
*
Thank you. The 10 films listed in alphabetical order are:
Dead
Of Night
Dead
Ringers
HellBound
HellRaiser
In
The Mouth Of Madness
Master
Of Illusions
Nightmare
On Elm Street
Prince
Of Darkness
Repulsion
The
Cube
War
Of The Worlds
What to submit to your submit directory:
O God, the Creator and Preserver of all
mankind, we humbly beseech thee for all sorts and conditions of men.
- Prayer Book, 1662