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

                4. [after §7.5] Suppose a Computer class contains, along with other instance variables, a hardDrive string instance variable. Complete the following swapHardDrive method that swaps the calling object’s hard drive value with the passed-in parameter’s hard drive value.
public void swapHardDrive(Computer otherComputer)
{
<insert code here>
} // end swapHardDrive
5. [after §7.5] Normally, we give each object a unique name by assigning its address to only one reference variable. Assigning the value of one reference variable to another reference variable creates two different names for the same thing, which is ambiguous. Identify a situation where this kind of assignment is useful, even though there is name ambiguity.
6. [after §7.6] Given this automobile-specification program:
1 /**************************************************************
10
11
{
12
public static void main(String[] args)
13
{
14
Scanner stdIn = new Scanner(System.in);
String serial;
AutoOptions auto = new AutoOptions();
System.out.print("Enter serial number: ");
serial = stdIn.nextLine();
auto.specifyEngine(auto.setSerial(serial).
specifyFrame().specifyBody().isTight());
auto.specifyTransmission();
auto.printOptions();
// end main
15
16
17
18
19
20
21
22
23
24
}
25
}
// end class AutoOptionsDriver
2 *
3 *
4*
5
AutoOptionsDriver.java
Dean & Dean
This exercises the AutoOptions class.
**************************************************************/
6
7
8
import java.util.Scanner;
     Apago PDF Enhancer
public class AutoOptionsDriver
9
1
/************************************************************
2
*
AutoOptions.java
Dean & Dean
This class records options for "custom" automobiles.
3
*
4*
5
6
*
7
*
*************************************************************/
Exercises 287



























   319   320   321   322   323