Allan Didier

Selection Sort


Students will demonstrate their ability to sort objects using the Selection Sort algorithm.

Program Details

Create a program that uses the Selection sort technique to sort and array of Persons. See the Selection Sort page for a more detailed explanation of the Selection Sort algorithm.

Your program needs:

  1. Person Class.
    1. Private variables
      1. First Name
      2. Last Name
      3. Phone number
    2. One constructor class that instantiates the variables by passing them in directly.
    3. Setter and Getter methods for each variable. Default Eclipse ones are fine.
    4. A toString method to output the variables in a readable fashion.
  2. Main Program. The main programs should sort an array of Persons using the Selection Sort technique. The main program should have the following.
    1. An array of 10 Persons instantiated by passing in the values directly.
    2. Sorts the array of people by last name using the Selection sort technique. Sort them alphabetically from a to z. Use the String method compareTo  to determine the order. 
    3. Print the array during each major iteration of sorting to see how the sorting works. Print the array after each iteration of your main outer for loop (for i), not the inner loops (j and k).
    4. Prints both the original, unordered array as well as the ordered array.


Java Textbook

Chapter 10: Polymorphism

Bill Barnum's AP Computer Science A videos

AP College Board test prep videos

AP College Board Video: Sorting

Geeks for Geeks: text explanation