import java.util.*; /* This program demonstrates decoupled code * Notice how this main program never refers to the actual classes of the various kinds of * people. * * Notice also that, by using a generic ArrayList no casting is * required in the for loops. (This code demonstrates the new style for-loop * * Finally notice that when you create a new class like Staff, nothing needs to be changed * in the tester * * This program obtains a list of people and then categorizes them by their * actual class names. */ public class Tester{ public static void main(String[] args){ //Create ArrayLists to hold some Persons objects and the different class names ArrayList people; //Arraylist of Person objects obtained from PeopleFactory //This needs to be initialized. ArrayList classNames = new ArrayList(); //can be used to hold class names /* *1) Initialize the people ArrayList so it contains the people provided by the * PersonFactory class * *2) Loop through the people ArrayList using the: * for(Person: aPerson: people){...} * style of for-loop * *3) Have your for-loop produce the sample output shown. * Note to obtain the name of an object's class you can use the * expression: * String className = anObject.getClass().getName(); * * */ //Print out how many different kinds of people there are and their class names System.out.println(classNames.size() + " kinds of people: " + classNames); } //end main } //end class Tester /* Sample output for Problem 1A 3 kinds of people: [Person, Student, Professor] The kinds of people ===================== Persons: ----------- Lou Britney Students: ----------- Sue #12345 Anne #12346 Frank #12347 Professors: ----------- Prof. Morrison emp#12345 Prof. Nel emp#12346 */ /* Sample output for Problem 1B 5 kinds of people: [Person, Student, Professor, TA, Staff] The kinds of people ===================== Persons: ----------- Lou Britney Students: ----------- Sue #12345 Anne #12346 Frank #12347 Professors: ----------- Prof. Morrison emp#12345 Prof. Nel emp#12346 TAs: ----------- COMP1405 TA: Terri #12348 COMP1405 TA: Glenn #12349 Staffs: ----------- Linda Staff: Comp Sci, Administrator John Staff: Comp Sci, Tech Support */