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

                43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
void calculateCost()
}
// end class PcDesign
{
}
// end calculateCost
this.cost = this.ramSize / 10000000.0 +
this.diskSize / 100000000.0;
if (this.processor.equals("Intel"))
{
}
else
{
}
this.cost += 400;
this.cost += 300;
//********************************************************
public void printSpecification()
{
}
System.out.println("RAM = " + this.ramSize);
System.out.println("Hard disk size = " + this.diskSize);
System.out.println("Processor = " + this.processor);
System.out.println("Cost = $" + this.cost);
// end printSpecification
Apago PDF Enhancer
Use the following trace setup to trace the PC-design program. Note that we have used abbreviations to keep the trace setup’s width as small as possible. Don’t forget to specify default and initial values even if they don’t impact the final result.
input
60000000000
Intel
Exercises 239
     Driver
PcDesign
                      line#
main
myPc
line#
aRSize
this
assignDiskSize
this
diskSize
aProc
this
cCost
this
printS
this
ramSize
obj1
  dSize
proc
cost
output
    7. [after §6.8]The answer to this exercise is not in the book—you’ll need to look elsewhere. Who are UML’s “Three Amigos”?
8. [after §6.8] Construct a UML class diagram for files in a computer directory. The class name should be
File. Include the following methods: public
public boolean isHidden().Alsoincludetheinstancevariableassociatedwiththefirstofthese methods. Include indication of whether the member is public or private and the type of the return value or variable. A File class already exists as part of the Java language, and this class also has many other methods, but the API library documentation for this class does not show any instance variables. Does that mean this class has no instance variables?
9. [after §6.9] If an object calls the same method two separate times, in the second execution, the method’s local variables begin with the values they had at the end of the previous execution of that method. (T / F)
String
getName(), public
long length(), and













   271   272   273   274   275