CompSci 4 - Classwork - Nov 29, 2005
5 pts

Today's classwork goes along with Chapter 10, section 2. You will be manipulating an array again.

  1. We will be modifying your Alice world from last class. You might want to make a copy of the world with a different name for today's classwork.

  2. Write a world method called Shuffle that swaps the object at each position in the array with a random object in another position. You should use loop (complicated version). This method has no parameters.

  3. Write a new world method called test and call Shuffle to test it out.

  4. Modify the world function indexOfSmallestHeight that you wrote last class. That function returns the index position of the person in the array with the smallest height. (note this returns the index, not the object). Modify it to add an integer parameter called startPos. The function should now return the index position of the person in the array with the smallest height, considering only those objects in position startPos to the end of the array.

  5. Add code to world.test to test indexOfSmallestHeight.

  6. Write the method world.SelectionSort to sort the people in the array by their heights. Use the SelectionSort algorithm discussed in class. You should call indexOfSmallestHeight inside a loop to find the position of the next smallest, and then swap it with the object that is in the position where the next smallest belongs in sorted order.
  7. At the end of world.test, call world.SelectionSort to test it out.

If you finish early, feel free to embelish your animations.