Java 2 exercises

profilesehj
a7_ex7.html

COMP 1020

 

Exercise #7

Download the ArrayList-based sorting students program from version 3 and add the following features to it:

  1. Rewrite the selection sort for arrays to sort the students in an ArrayList by name. This new sortByName method will be an instance method, and it should be private. Sort the array list's contents directly yourself, do not copy the items to a regular array or call any built-in Java methods.
  2. Call your sort method from a printByName instance method that makes a copy of the ArrayList by calling its clone() method and prints it. Note: to make clone() work, you need to cast the result to the correct type; call it as follows: (ArrayList<Student>)list.clone(). The Java compiler may give you a warning, which is not the same as an error. Your program should still run, and give correct output.

Submit the complete revised StudentList class by the due date specified in the course schedule.