Page 249 - Introduction to Programming with Java: A Problem Solving Approach
P. 249
method call, you have two choices. You can “step into” and go through all the statements
in the called method, like we do in Figure 6.11, or you can “step over” and just see what
happens after the method returns. In a typical debugging activity, you will use a combina- debugger. tion of stepping over and stepping in. For the example problem we have been considering,
the sample session in Figure 6.8 tells you that the simulation is OK for the first object. The problem is with the second object. So, the appropriate thing to do is step over the method calls down through line 23 in the MouseDriver2 class. Then, starting at line 24 in the MouseDriver2 class, step into the methods calls to zero in on what caused the problem.
6.8 UML Class Diagrams
The Mouse class’s grow method is not very flexible—it forces the driver to call the grow method sepa- rately for each day or to provide a for loop for each multiple-day simulation. It isn’t good style to include such things in a driver. It’s better to include multiple-day functionality within the driven class. In this sec- tion, we do just that. We present a revised mouse class with a grow method that handles any number of days, not just one day.
To specify a second-generation mouse class (Mouse2) and an associated driver class Organize. (Mouse2Driver), let’s create another UML class diagram. The diagram we presented in
Figure 6.3 was a pared-down UML class diagram. It did not include all the standard features. This time, in Figure 6.12, we present a UML class diagram that includes all the standard features, plus an extra feature.
6.8 UML Class Diagrams 215
Paper trace emulates IDE
Figure 6.12’s class diagram includes class diagram boxes for both classes—one diagram for the Mouse2Driver class and another diagram for the Mouse2 class. The Mouse2 class has the same three
Apago PDF Enhancer
instance variables as the original Mouse class—age, weight, and percentGrowthRate. It also has the same setPercentGrowthRate method. But the getAge and getWeight methods are new and the
Mouse2Driver
+main() : void
main :
stdIn : Scanner mickey : Mouse2 days : int
Mouse2
‒age : int = 0
‒weight : double = 1.0 ‒percentGrowthRate : double
+setPercentGrowthRate(percentGrowthRate : double) : void +getAge() : int
+getWeight() : double
+grow(days : int) : void
Figure 6.12
A UML class diagram for a second-generation Mouse program
UML notes use dashed lines and bent top-right corners.
grow: i : int