Problem

Given this automobile-specification program:1 /*******************************************...

Given this automobile-specification program:

1 /**************************************************************2 * AutoOptionsDriver.java3 * Dean&Dean4 *5 * This exercises the AutoOptions class.6 **************************************************************/ 78 import java.util.Scanner; 910 public class AutoOptionsDriver11 {12 public static void main(String[] args)13 {14 Scanner stdIn = new Scanner(System.in);15 String serial;16 AutoOptions auto = new AutoOptions(); 1718 System.out.print("Enter serial number: ");19 serial = stdIn.nextLine();20 auto.specifyEngine(auto.setSerial(serial).21 specifyFrame().specifyBody().isTight());22 auto.specifyTransmission();23 auto.printOptions();24 } // end main25 } // end class AutoOptionsDriver

1 /************************************************************2 * AutoOptions.java3 * Dean&Dean4 *5 * This class records options for "custom" automobiles.6 *************************************************************/78 import java.util.Scanner;910 public class AutoOptions11 {12 private String serial; // automobile serial number13 private char frame = 'x'; // frame type: A,B14 private String body = ""; // body style: 2Door,4Door15 private int hp = 0; // engine horsepower: 85, 115, 1651617 // transmission: false = manual, true = automatic18 private boolean automatic = false;1920 //****************************************************************2122 public AutoOptions setSerial(String serial)23 {24 this.serial = serial;25 return this;26 } // end setSerial2728 //****************************************************************2930 public AutoOptions specifyFrame()31 {32 Scanner stdIn = new Scanner(System.in);3334 while (this.frame != 'A' && this.frame != 'B')35 {36 System.out.print("Enter frame (A or B): ");37 this.frame = stdIn.nextLine().charAt(0);38 } // end while39 return this;40 } // end specifyFrame4142 //****************************************************************4344 public AutoOptions specifyBody()45 {46 Scanner stdIn = new Scanner(System.in);4748 while (!this.body.equals("2-door")49 && !this.body.equals("4-door"))50 {51 System.out.print(52 "Enter (2-door or 4-door): ");53 this.body = stdIn.nextLine();54 } // end while55 return this;56 } // end specifyBody5758 //*********************************************************5960 public boolean isTight()61 {62 boolean tight = false;6364 if (this.frame == 'A' && this.body.equals("4-door"))65 {66 tight = true;67 }68 return tight;69 } // end isTight7071 //*********************************************************7273 public void specifyEngine(boolean tight)74 {75 Scanner stdIn = new Scanner(System.in);7677 if (tight)78 {79 while (this.hp != 85 && this.hp != 115)80 {81 System.out.print("Enter HP (85 or 115): ");82 this.hp = stdIn.nextInt();83 } // end while84 }85 else86 {87 while (this.hp != 85 && this.hp != 115 && this.hp != 165)88 {89 System.out.print("Enter HP (85, 115, 165): ");90 this.hp = stdIn.nextInt();91 } // end while92 } // end if tight else93 stdIn.nextLine(); // flush \r\n after nextInt94 } // end specifyEngine9596 //*********************************************************9798 public void specifyTransmission()99 {100 Scanner stdIn = new Scanner(System.in);101102 System.out.print("Automatic (y/n?): ");103 if (stdIn.nextLine().charAt(0) == 'y')104 {105 this.automatic = true;106 }107 } // end specifyTransmission108109 //***********************************************************110111 public void printOptions()112 {113 System.out.printf("serial# %s\n%s frame\n%s\n%-3d HP\n",114 this.serial, this.frame, this.body, this.hp);115 if (automatic)116 {117 System.out.println(" automatic");118 }119 else120 {121 System.out.println("4-speed manual");122 }123 } // end printOptions124 } // end class AutoOptions

Use the following trace setup to trace the Auto Options program. Note that we have used abbreviations to keep the trace setup’s width as small as possible.

input

X142R

A

4-door

165

115

Y

AutoOptionsDriver

AutoOptions

line#

main

line#

setSerial

spec Frame

spec Body

isTight

specEngine

spec Trans

print Opt

obj1

ser

auto

this

ser

this

this

this

tight

this

tight

this

this

ser

frm

body

hp

auto

output

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
Solutions For Problems in Chapter 7
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT