06_lewis_409167_labMan06

06_lewis_409167_labMan06 - Chapter 6: Object-Oriented...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
98 Chapter 6: Object-Oriented Design Chapter 6: Object-Oriented Design Lab Exercises Topics Lab Exercises Parameter Passing Changing People Interfaces Using the Comparable Interface Method Decomposition A Modified MiniQuiz Class Overloading A Flexible Account Class A B i a s e d C o i n Static Variables Opening and Closing Accounts and Methods Counting Transactions Transfering Funds Overall class design Random Walks GUI Layouts Telephone Keypad
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Chapter 6: Object-Oriented Design 99 Changing People The file ChangingPeople.java contains a program that illustrates parameter passing. The program uses Person objects defined in the file Person.java. Do the following: 1. Trace the execution of the program using diagrams similar to those in Figure 6.5 of the text (which is a trace of the program in Listings 6.15 – 6.17). Also show what is printed by the program. 2. Compile and run the program to see if your trace was correct. 3. Modify the changePeople method so that it does what the documentation says it does, that is, the two Person objects passed in as actual parameters are actually changed. // ********************************************************************** // ChangingPeople.java // // Demonstrates parameter passing -- contains a method that should // change to Person objects. // ********************************************************************** public class ChangingPeople { // --------------------------------------------------------- // Sets up two person objects, one integer, and one String // object. These are sent to a method that should make // some changes. // --------------------------------------------------------- public static void main (String[] args) { Person person1 = new Person ("Sally", 13); Person person2 = new Person ("Sam", 15); int age = 21; String name = "Jill"; System.out.println ("\nParameter Passing. .. Original values. .."); System.out.println ("person1: " + person1); System.out.println ("person2: " + person2); System.out.println ("age: " + age + "\tname: " + name + "\n"); changePeople (person1, person2, age, name); System.out.println ("\nValues after calling changePeople. .."); System.out.println ("person1: " + person1); System.out.println ("person2: " + person2); System.out.println ("age: " + age + "\tname: " + name + "\n"); } // ------------------------------------------------------------------- // Change the first actual parameter to "Jack - Age 101" and change // the second actual parameter to be a person with the age and // name given in the third and fourth parameters. // ------------------------------------------------------------------- public static void changePeople (Person p1, Person p2, int age, String name) { System.out.println ("\nInside changePeople. .. Original parameters. .."); System.out.println ("person1: " + p1); System.out.println ("person2: " + p2); System.out.println ("age: " + age + "\tname: " + name + "\n");
Background image of page 2
100 Chapter 6: Object-Oriented Design // Make changes Person p3 = new Person (name, age);
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 21

06_lewis_409167_labMan06 - Chapter 6: Object-Oriented...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online