import java.lancs.Person; import java.lancs.BasicIo; import java.util.Vector; import java.util.Enumeration; public class People { public static void main (String[] args) throws Exception { // Create a collection Vector people = new Vector (); // Add three Person objects to the Collection for (int i = 1; i <= 3; i++) { System.out.println (); // Create a new Person Person person = new Person (); // Get and set the forename System.out.print ("Enter forename: "); person.setForename (BasicIo.readString ()); // // Other Person attributes removed for simplicity // // Add person to collection people.addElement (person); } System.out.println (); // Print the vector; this will print the entire collection System.out.println (); System.out.println ("Printing the vector"); System.out.println (); System.out.println (people); System.out.println (); System.out.println (); System.out.println ("Printing one person at a time"); System.out.println (); // Extract the elements one at a time; careful of i for (int i = 0; i <= 2; i++) { Person person = (Person) people.elementAt (i); System.out.println ("Person's forename is: " + person.getForename ()); } System.out.println (); System.out.println (); System.out.println ("Printing one person at a time (using Enumeration)"); System.out.println (); // Extract the elements one at a time; this approach uses the // enumeration Enumeration iterator = people.elements (); while (iterator.hasMoreElements ()) { Person person = (Person) iterator.nextElement (); System.out.println ("Person's forename is: " + person.getForename ()); } System.out.println (); } }