Page 274 - Introduction to Programming with Java: A Problem Solving Approach
P. 274

                240 Chapter 6 Object-Oriented Programming
10. [after §6.9] Trace the Mouse2 program shown in Figures 6.13 and 6.14. Use the following trace setup. Note
that we have used abbreviations to keep the trace setup’s width as small as possible.
input
2
11. [after §6.11] The diagram below shows Mouse2 program methods, with their parameters and local variables indented, and the one instantiated object, with its instance variables indented. Your task is to construct a time line for each method, local variable or parameter, object, and instance variable. Each time line should show that item’s persistence (when it starts and ends) relative to the other items. To help you get started we have provided the time lines for the main method and one of its local variables. Provide all the other time lines, and show how they align with each other and those already provided. (Assume that the object and its instance variables come into existence simultaneously.)
    Mouse2Driver
Mouse
                     line#
mickey
main
line#
setPGR
this
rate
getAge
this
getWt
this
this
grow
days
i
age
obj1
   days
wt
rate
output
    methods:
main
mickey
days
setPercentGrowthRate
getAge
getWeight
grow
time →
|------------------------|
|-----------------------|
days
i
object:
mickey
age
weight
Apago PDF Enhancer
percentGrowthRate
12. [after §6.12] Complete the following StudentIdDriver class skeleton by replacing all six occurrences of <insert-code-here> with your own code such that the program operates properly. For details, read the comments above or next to the <insert-code-here> insertions. Note the StudentId class, which is below the StudentIdDriver class. The two classes are in separate files.
import java.util.Scanner;
public class StudentIdDriver
{
public static void main(String[] args)
{
Scanner stdIn = new Scanner(System.in);
StudentId student;











































   272   273   274   275   276