Question: In the main method, create two Odometer objects and adds on miles and outputs the amount of gas consumed. Include, two test trips, one with
In the main method, create two Odometer objects and adds on miles and outputs the amount of gas consumed. Include, two test trips, one with a car at 45 MPG, the other at 13 MPG.
MPG - Miles per Gallon
/
* Question3Odometer.java
*
* This program defines an Odometer class to track fuel and mileage.
* It stores the miles driven and fuel efficient and includes a function to calculate the number of gallons of gasoline consumed.
*
* Created: 2023
*
* @author Your Name
* @version 1
*/
public class Question3Odometer
{
private int miles; // Miles driven
private double fuel_efficiency; // Miles/Gallon for the vehicle
/
* Default constructor; Initialize to common values.
*/
public Question3Odometer()
{
miles=0; // Default values
fuel_efficiency=15;
}
/
* Odometer constructor; Initialize fuel efficiency.
*
* @param fuel_efficiency The new fuel efficiency.
*/
public Question3Odometer(double fuel_efficiency)
{
miles=0;
this.fuel_efficiency=fuel_efficiency;
}
/
* Sets fuel effienciency to a new value.
*
* @param fuel_efficiency The new fuel efficiency.
*/
public void setFuelEfficiency(double newEfficiency)
{
fuel_efficiency = newEfficiency;
}
/
* Resets miles travelled to zero.
*/
public void resetMiles()
{
miles=0;
}
/
* Upon completing a drive, this method adds on the miles
* driven to the odometer.
*
* @param additionalMiles Number of new miles driven and to be added to the odometer
*/
public void logMiles(int additionalMiles)
{
miles += additionalMiles;
}
/**
* Sets fuel effienciency to a new value.
*
* @return number of gallons of gas consumed on this trip
*/
public double gasConsumed()
{
return (miles / fuel_efficiency);
}
} // End of the Question
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
