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

                32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
{
}
// end class Shirt
System.out.println(this.name + "'s shirt:\n" +
this.primary + " with " + this.trim + " trim");
} // end display
//*********************************************************
// Helping method prompts for and inputs user's selection
private String selectColor(String colorType)
{
}
// end selectColor
Scanner stdIn = new Scanner(System.in);
String color; // chosen color, first a letter, then word
do
{
System.out.print("Enter shirt's " + colorType +
" color (w, r, y): ");
color = stdIn.nextLine();
while (!color.equals("w") && !color.equals("r") &&
!color.equals("y"));
switch (color.charAt(0))
}
{
}
// end switch
caseA'pw'a: go PDF Enhancer
color =
break;
case 'r':
color =
break;
case 'y':
color =
"white";
"red";
"yellow";
return color;
Trace the above shirt-design program using either the short form or the long form. To help you get started, here’s the trace setup, including the input. For the short form, you won’t need the line# column.
input
Corneal r
w
Jill
w y
Exercises 339
    ShirtDriver
Shirt
            line#
main
Shirt
display
selectColor
obj1
obj2
               sh1
sh2
line#
this
this
this
cType
color
name
prim
trim
name
prim
trim
output
 
   371   372   373   374   375