public class TestProgComposition { public static void main(String[] arg) { PersonalInfo student1 = new PersonalInfo("William", "Jordan", 8, 24, 1963, 555238911); PersonalInfo student2 = new PersonalInfo(); /* THE FOLLOWING ARE PROBLEMATIC. CAN YOU SEE WHY? student2.setFirstName("Allison"); student2.name.setFirstName("Allison"); There is no setFirstName in the PersonalInfo class. Also, there is no firstName field for a PersonalInfo object (student2) The second attempt is better, but still not perfect since 'name' is a private field and cannot be accessed directly. The following WOULD work: Person n = student2.getName(); //n now points to the name object of student2 n.setName("Allison", "Smith"); Another, perhaps better way is just below: */ student2.getName().setName("Allison","Smith"); //Note that we need to retrieve the reference to name by invoking the getName() method //More examples using composition: String name = student1.getName().getFirstName(); //Set first name to "Lisa" student1.getName().setFirstName("Lisa"); //Set birth year to 1968 student1.getBDay().setYear(1968); // The key issue is to recognize how the dot operator is used. // student1.name.firstName = "William"; --> can't do this (firstName is private inside the Person class) // Also, the 'name' field is private inside the PersonalInfo class // Proper command: student1.getName().setFirstName("William"); // student1.name.lastName is Jordan // Proper command: student1.getName().setLastName("Jordan"); // student1.bDay.dDay = 24 // Proper command: student1.getBDay().setDay(24); // change id to 55238911 student1.setPersonId(55238911); /* IMPORTANT: Notice how when we wish to make changes to fields such as the birthday, the designers of the PersonalInfo class conveniently provided methods to do so. For example, in order to set the birthdate, they wrote a method called setBirthday that invokes a method from the Date classe as needed. Here is an example: */ student2.setBirthday(1, 29, 1962); //As an exercise, try writing a setName method in the PersonalInfo class... System.out.println(student2); System.out.println(student1); } //end main } //end class TestProgComposition