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

                290
Chapter 7 Object-Oriented Programming—Additional Details
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
//***********************************************************
public void printOptions()
}
// end class AutoOptions
{
}
// end printOptions
System.out.printf("serial# %s\n%s frame\n%s\n%-3d HP\n",
this.serial, this.frame, this.body, this.hp);
if (automatic)
{
}
else
{
}
System.out.println(" automatic");
System.out.println("4-speed manual");
Use the following trace setup to trace the AutoOptions program. Note that we have used abbreviations to keep the trace setup’s width as small as possible.
input X142R
A4-door 165 115
Y
Apago PDF Enhancer
   AutoOptionsDriver
AutoOptions
                                  line#
ser
main
auto
line#
setSerial
ser
spec Frame
this
spec Body
this
this
isTight
tight
specEngine
this
tight
spec Trans
this
print Opt
this
ser
obj1
  this
frm
body
hp
auto
output
  7.
[after §7.6] In the following Time and TimeDriver class skeletons, replace the italicized <insert . . . > lines with your own code such that the program operates properly. More specifically:
a) In the Time class, provide a method definition for the setHours method such that setHours can be called as part of a method-call chain.
b) In the TimeDriver class, provide a single statement that chains calls to the setHours, set- Minutes, setSeconds, and printTime methods. Use reasonable values for your method-call arguments. If you pass 8 to setHours, 59 to setMinutes, and 0 to setSeconds, then your method-call-chaining statement should print this:
08:59:00
public class Time
private int hours;
private int minutes;
{
private int seconds;

















   322   323   324   325   326