Question: This assignment will contains two template files: Auto.java a class definition EvaluateAuto.java contains main() method Use the template files provided to complete the following exercises.
This assignment will contains two template files:
Auto.java a class definition
EvaluateAuto.java contains main() method Use the template files provided to complete the following exercises. And include complete JavaDoc style documentation for both files. Each step of the instructions is associated with specific tests, so you can test your program as you go along.
Templates:
Auto.java template
/**
* Class description
* @author
* @version
*/
public class Auto {
private String makeModel;
private int tankCapacity;
private int avgRange;
// Insert your code here
}
EvaluateAuto.java template:
/**
* Program description
* @author
* @version
*/
import java.util.InputMismatchException;
import java.util.Scanner;
public class EvaluateAuto {
public static void main(String[] args) {
// Insert your code here
}
}
Program Requirements
An automobile dealership needs to do calculations for their cars, based on the gas tank capacity and average range the car can travel on one tank of gas. Write a program to create objects that represent home mortgage loans.
Test 1: Within the EvaluateAuto class:
Write code to read an automobile make/model, gas tank capacity and average range the car can drive on one tank from the user, using the prompts as shown below.
After reading the both inputs, display a "Both inputs valid integers" message (no error checking required here)
Example:
Enter make and model of car: Honda Accord
Enter tank capacity (in whole gallons): 10
Enter average range (in whole miles): 250
Both inputs valid integers
Tests 2 through 4: Within the EvaluateAuto class:
Add an exception handler that includes:
A try block around the code that reads the second two user inputs.
If no exceptions are automatically thrown, the code will still display the same "Both inputs valid integers" message as before
A catch block to catch the InputMismatchException thrown if the user does not enter an integer for one of the integer inputs.
The catch block should display:
Error - did not enter a valid integer value
Test 5: Within the Auto class:
Add a constructor that has parameters for the data fields.
Add a getters for the data fields.
Test 6: Within the Auto class:
Add a calcMPG() method that will divide avgRange by tankCapacity to determine and return an integer containing the average whole mile per gallon the car gets (NOTE: use integer division to ignore any remainder).
Test 7: Within the EvaluateAuto class:
Add code to the try block in the main method to:
Display a blank line
Create an object with the user entered values as arguments to the constructor
Use the object created to call the calcMPG() method and display the results in this format:
Honda Accord gets approximately 10 miles per gallon
(using any necessary getters)
Test 8: Within the EvaluateAuto class:
Add a second catch block that will catch the ArithmeticException that may be automatically thrown when the calcMPG () method is called and the tank capacity is 0 during the division.
The catch block should display
Error - cannot determine mpg when tank capacity is 0
Test 9 to 11: Within the Auto class:
Add a displayMakeAd() method that will:
Find the first space in the makeModel string (that separates the make and model)
When the String does not contain a space, to throw a RuntimeException with the message "Error invalid make model"
Otherwise display only the make stored in the Auto object, within the following type of message: Always buy make!
For example: Always buy Honda!
Within the EvaluateAuto class:
Add code to the try block in the main method to:
Use the object created to call the displayMakeAd() method.
Add a third catch block that will catch the RuntimeException that may be thrown when the displayMakeAd() method is called.
The catch block should display the message from the RuntimeException object
Warning: Do NOT display a quoted String here display the message from the RuntimeException object
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
