Quiz 18 (Review Exercise)


  1. Write a class Person such that an array of Person objects can be sorted with java.util.Arrays.sort(Object[]) which compares objects using the compareTo(Object) method. Make it so that in the sorting female comes before male and secondly people with more friends come first. Each person has an array list of friends.
  2. Write an equals method for the class Person above, such that two person objects are equal if they are the same sex and they have the same friends. You cannot assume that the order of friends in the array list is the same.
  3. Write a subclass of Person called Child such that Child object has a mother. The equals method of child should equate two children if they are the same in terms of Person equality and if they have equal mothers.