Page 322 - Introduction to Programming with Java: A Problem Solving Approach
P. 322
288
Chapter 7 Object-Oriented Programming—Additional Details
9
10
public class AutoOptions
11
{
12
private String serial;
private char frame = 'x';
private String body = "";
private int hp = 0;
13
// automobile serial number
// frame type: A,B
// body style: 2Door,4Door
// engine horsepower: 85, 115, 165
// transmission: false = manual, true = automatic
private boolean automatic = false;
//****************************************************************
public AutoOptions setSerial(String serial)
14
15
16
17
18
19
20
21
22
23
{
24
this.serial = serial;
return this;
// end setSerial
//****************************************************************
25
26
}
27
28
29
30
public AutoOptions specifyFrame()
31
{
32
Scanner stAdIpna=gneow ScPanDneFr(SyEstnemh.ian)n;cer while (this.frame != 'A' && this.frame != 'B')
33
34
35
{
36
System.out.print("Enter frame (A or B): ");
this.frame = stdIn.nextLine().charAt(0);
// end while
37
38
}
39
return this;
40
}
// end specifyFrame
41
42
//****************************************************************
43
44
public AutoOptions specifyBody()
45
{
46
Scanner stdIn = new Scanner(System.in);
while (!this.body.equals("2-door")
&& !this.body.equals("4-door"))
System.out.print(
"Enter (2-door or 4-door): ");
this.body = stdIn.nextLine();
// end while
47
48
49
50
{
51
52
53
54
}
55
return this;
56
}
// end specifyBody
57
8
import java.util.Scanner;