Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a program in Java to compute the following properties of automobiles: average gas mileage, lowest price, the latest model. The program must have the
Write a program in Java to compute the following properties of automobiles: average gas mileage,
lowest price, the latest model. The program must have the following:
A class named Automobile library
One constructor function that initializes the model year only.
A method to set the gas mileage and price for the object variables.
Three separate methods to compute the results average gas mileage, lowest price, latest
model and show the outputs.
The Main function will stay in another class test or main class from where the
constructors and all other methods will be invoked through three objects named: sedan,
minivan, and truck.
Inputs are to be taken inside the Main function from the keyboard. The program will show
the outputs on the screen.
Sample Input from keyboard:
Enter the model year for sedan:
Enter the gas mileage for sedan:
Enter the price for sedan:
Enter the model year for minivan:
Enter the gas mileage for minivan:
Enter the price for minivan:
Enter the model year for truck:
Enter the gas mileage for truck:
Enter the price for truck:
Sample Output on screen:
Avg gas mileage:
Lowest price:
Latest model: i am not allowed to use inheritance in this code and i have written a little bit of it as well package Objects;
class Automobile
private int model;
private double gasMileage;
private double lowestPrice;
public Automobileint newModel
model newModel;
public void setgasMileagedouble newGasMileage
gasMileage newGasMileage;
public void setpricedouble price
lowestPrice price;
public double getGasMileage
return gasMileage;
public double getLowestPrice
return lowestPrice;
public int getLatestModel
return model ;
package Objects;
import java.util.Scanner;
public class TestAutomobile
public static void mainString args
Scanner input new ScannerSystemin;
System.out.printEnter the model year for sedan: ;
int sedanYear input.nextInt;
System.out.printEnter the gas mileage for sedan: ;
double sedanMileage input.nextDouble;
System.out.printEnter the price for sedan: ;
double sedanPrice input.nextDouble;
System.out.printEnter the model year for minivan: ;
int minivanYear input.nextInt;
System.out.printEnter the gas mileage for minivan: ;
double minivanMileage input.nextDouble;
System.out.printEnter the price for minivan: ;
double minivanPrice input.nextDouble;
System.out.printEnter the model year for truck: ;
int truckYear input.nextInt;
System.out.printEnter the gas mileage for truck: ;
double truckMileage input.nextDouble;
System.out.printEnter the price for truck: ;
double truckPrice input.nextDouble;
Automobile sedan new AutomobilesedanYear;
sedan.setgasMileagesedanMileage;
sedan.setpricesedanPrice;
Automobile minivan new AutomobileminivanYear;
minivan.setgasMileageminivanMileage;
minivan.setpriceminivanPrice;
Automobile truck new AutomobiletruckYear;
truck.setgasMileagetruckMileage;
truck.setpricetruckPrice;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started