Page 248 - Introduction to Programming with Java: A Problem Solving Approach
P. 248
214 Chapter 6 Object-Oriented Programming
input
10
MouseDriver2
Mouse
line#
main
line#
setPGR
grow
disp
obj1
obj2
rate
gus
jaq
this
rate
this
this
age
wt
rate
age
wt
rate
output
15
?
16
?
?
18
Enter % growth rate:
19
10.0
20
10
11
12
0
1.000
0.0
20
obj1
21
obj1
10.0
22
20
10.0
obj1
29
1.100
31
1
23
obj1
40
Apago
P
DF
E
nhancer
Age 1, weight 1.100
24
10
11
0
1.000
12
0.0
24
25
obj2
29
obj2
1.000
31
1
26
obj2
40
Age 1, weight 1.000
Figure 6.11 Completed trace for the Mouse program
Now that we’ve walked you through the new techniques for tracing an OOP program, we encourage you to go back to the trace setup in Figure 6.10 and do the entire trace on your own. Pay particular attention to what happens when gus and jaq call the grow method. Verify that gus’s weight increases (as it should) and jaq’s weight fails to increase (a bug). When you’re done with the trace,
compare your answer to Figure 6.11.
Experience with the long-form tracing used in this book will make it easier for you to understand
what an automated debugger in an Integrated Development Environment (IDE) is telling you. As you step through a program that’s running in debug mode under the control of an IDE debugger, when you get to a
Practice.