Write a FancyCar class to support basic operations such as drive, add gas, honk horn, and start engine. FancyCar.java is provided with method stubs. Follow each step to gradually complete all methods. Note: This program is designed for incremental development. Complete each step and submit for grading before starting the next step. Only a portion of tests pass after each step but confirm progress. The main() method includes basic method calls. Add statements in main() as methods are completed to support development mode testing. Step 0. Declare private fields for miles driven as shown on the odometer (int), gallons of gas in tank (double), miles per gallon or MPG (double), driving capacity (double), and car model (String). Note the provided final variable indicates the gas tank capacity of 14.0 gallons. Step 1 (2 pts). 1) Complete the default constructor by initializing the odometer to five miles, tank is full of gas, miles per gallon is 24.0, and the model is "Old Clunker". 2) Complete the second constructor by passing the model (String) and miles per gallon (double), and initializing all other private fields the same as the default constructor. 3) Complete the accessor methods to check the odometer, check the gas guage, get the model, and get the miles per gallon. Submit for grading to confirm 2 tests pass. Step 2 (1 pt). Complete the honkHorn() method to output the car model. Calling the honkHorn() method uses the model private field to provide the following output: The Honda Civic says beep beep! Submit for grading to confirm 3 tests pass. Step 3 (1 pt). Complete the drive() method. Miles driven should increase by parameter distance and amount of gas should decrease by distance / MPG. Variables are only updated if parameter distance is positive. Submit for grading to confirm 4 tests pass. Step 4 (2 pts). Complete the addGas() method. Increase gas tank by parameter amount only if parameter is positive. Set gas tank to FULL if too much gas was added. Submit for grading to confirm 5 tests pass. Step 5 (2 pts). Update the drive() method to identify if the car runs out of gas. If so, the parameter distance will not be achieved and the gas tank will have 0.0 gallons. Ex: drive(100) will not be possible with only three gallons of gas and MPG of 20.0. The maximum driving distance is 60 miles with three gallons of gas and MPG of 20.0. Therefore, the odometer will only increase by 60 instead of the requested 100 and the gas tank will have 0.0 gallons (not a negative amount). Submit for grading to confirm 6 tests pass. Step 6 (2 pts). 1) Add a boolean private field to indicate if the car engine is on or off. 2) Complete the startEngine() method to set the boolean variable to true. 3) Complete the stopEngine() method to set the boolean variable to false. 4) Update the constructors to start with the engine off. 5) Update the drive() method to only update private fields if the engine is on, and the engine turns off if the car runs out of gas. 6) Update the addGas() method to only add gas if the engine is off. Submit for grading to confirm all tests pass.
Write a FancyCar class to support basic operations such as drive, add gas, honk horn, and start engine. FancyCar.java is provided with method stubs. Follow each step to gradually complete all methods.
Note: This program is designed for incremental development. Complete each step and submit for grading before starting the next step. Only a portion of tests pass after each step but confirm progress. The main() method includes basic method calls. Add statements in main() as methods are completed to support development mode testing.
Step 0. Declare private fields for miles driven as shown on the odometer (int), gallons of gas in tank (double), miles per gallon or MPG (double), driving capacity (double), and car model (String). Note the provided final variable indicates the gas tank capacity of 14.0 gallons.
Step 1 (2 pts). 1) Complete the default constructor by initializing the odometer to five miles, tank is full of gas, miles per gallon is 24.0, and the model is "Old Clunker". 2) Complete the second constructor by passing the model (String) and miles per gallon (double), and initializing all other private fields the same as the default constructor. 3) Complete the accessor methods to check the odometer, check the gas guage, get the model, and get the miles per gallon. Submit for grading to confirm 2 tests pass.
Step 2 (1 pt). Complete the honkHorn() method to output the car model. Calling the honkHorn() method uses the model private field to provide the following output:
The Honda Civic says beep beep!
Submit for grading to confirm 3 tests pass.
Step 3 (1 pt). Complete the drive() method. Miles driven should increase by parameter distance and amount of gas should decrease by distance / MPG. Variables are only updated if parameter distance is positive. Submit for grading to confirm 4 tests pass.
Step 4 (2 pts). Complete the addGas() method. Increase gas tank by parameter amount only if parameter is positive. Set gas tank to FULL if too much gas was added. Submit for grading to confirm 5 tests pass.
Step 5 (2 pts). Update the drive() method to identify if the car runs out of gas. If so, the parameter distance will not be achieved and the gas tank will have 0.0 gallons. Ex: drive(100) will not be possible with only three gallons of gas and MPG of 20.0. The maximum driving distance is 60 miles with three gallons of gas and MPG of 20.0. Therefore, the odometer will only increase by 60 instead of the requested 100 and the gas tank will have 0.0 gallons (not a negative amount). Submit for grading to confirm 6 tests pass.
Step 6 (2 pts). 1) Add a boolean private field to indicate if the car engine is on or off. 2) Complete the startEngine() method to set the boolean variable to true. 3) Complete the stopEngine() method to set the boolean variable to false. 4) Update the constructors to start with the engine off. 5) Update the drive() method to only update private fields if the engine is on, and the engine turns off if the car runs out of gas. 6) Update the addGas() method to only add gas if the engine is off. Submit for grading to confirm all tests pass.
Unlock instant AI solutions
Tap the button
to generate a solution