Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello, I am working on a java program and I am stuck. Let me post the code down below. ---------------------------------------------------------------------------------------------------- package edu.vt.cs5044; /** * A

Hello,

I am working on a java program and I am stuck. Let me post the code down below.

----------------------------------------------------------------------------------------------------

package edu.vt.cs5044;

/** * A basic vehicle Fuel Monitor. * * Objects of this class track a vehicle's fuel usage and miles-per-gallon (MPG) efficiency, over * single trips and the lifetime of the object. The vehicle has two modes of operation, green mode * and sport mode, which have significantly different fuel efficiencies. * * Academic Note: In this project, you don't need to worry about validating the values received by * any of the methods. All parameters should be presumed valid and used as is. For example, you may * safely assume that the miles driven and fuel used will always be non-negative. * * Academic Note: Neither branches nor loops are required. Only primitive types int and double * should be used. The implementation must not use Math.round() or any other library. All * calculations should be performed at double precision, with only the final result being truncated * (where applicable) via arithmetic and casting. * * @author Prof.O * @version 2017.Summer */ public class FuelMonitor {

private int eachTripMileage; private int lifetimeMileage ; private int greenModeMileage; private int sportModeMileage; private double eachTripFuelUsage; private double lifetimeFuelUsage; private double sportModeFuelUsage; private double greenModeFuelUsage; private double fuelLevel; /** * Creates a new FuelMonitor object. * * The constructor will initialize the lifetime and trip miles counters to zero, and initialize * the fuel tank to be as specified. The first trip is implicitly started upon construction. * * @param initialFuel the starting amount of fuel in the tank, in gallons. */ public FuelMonitor(double initialFuel) { lifetimeMileage = 0; eachTripMileage =0; greenModeMileage =0; sportModeMileage=0; fuelLevel = initialFuel; }

/** * Indicate miles driven and gallons used in green mode. * * This method is called periodically by other components, as miles are driven and/or fuel is * used, while the vehicle is in green mode. * * @param miles number of miles driven. * @param gallons amount of fuel used. */ public void useInGreenMode(int miles, double gallons) { lifetimeMileage += miles; lifetimeFuelUsage += gallons; greenModeMileage += miles; greenModeFuelUsage += gallons; eachTripMileage += miles; eachTripFuelUsage += gallons; fuelLevel -= gallons; }

/** * Indicate miles driven and gallons used in sport mode. * * This method is called periodically by other components, as miles are driven and/or fuel is * used, while the vehicle is in sport mode. * * @param miles number of miles driven. * @param gallons amount of fuel used. */ public void useInSportMode(int miles, double gallons) { lifetimeMileage = lifetimeMileage + miles; lifetimeFuelUsage += gallons; sportModeMileage = sportModeMileage + miles; sportModeFuelUsage += gallons; eachTripMileage += miles; eachTripFuelUsage += gallons; fuelLevel -= gallons; }

/** * Indicate that fuel has been added to the vehicle. * * This method is called when the fuel tank has been partially or completely refilled. * * @param gallons amount of fuel added. */ public void addFuel(double gallons) { // TODO: Your implementation goes here fuelLevel += gallons; }

/** * Indicate that the trip meter has been reset. * * This method is called when the driver initiates a trip reset. This action completes the * current trip and begins a new trip. */ public void resetTrip() { // TODO: Your implementation goes here eachTripMileage = 0; eachTripFuelUsage = 0; sportModeMileage = 0; sportModeFuelUsage = 0; greenModeMileage = 0; greenModeFuelUsage = 0; } /** * Report the number of miles driven on the current trip. * * This includes all miles driven this trip, regardless of mode, since the last trip reset. * * @return miles driven this trip. */ public int getTripMiles() { // TODO: Your implementation goes here return greenModeMileage + sportModeMileage; // TODO: Replace this placeholder }

/** * Report the average fuel efficiency of the current trip, in miles per gallon (MPG). * * This includes all trip miles, consistent with getTripMiles(), and all fuel used during the * current trip. The result is rounded down (truncated) to a multiple of 0.1 MPG. * * Academic Note: This method won't be called until at least some fuel has been used this trip. * * @return truncated fuel efficency this trip. */ public double getTripMPG() { // TODO: Your implementation goes here double mpg = (eachTripMileage/eachTripFuelUsage) * 0.1; return mpg; // TODO: Replace this placeholder }

/** * Report the amount of fuel remaining, in gallons. * * The value returned is exact, not truncated. * * @return fuel currently in the tank. */ public double getFuelRemaining() { // TODO: Your implementation goes here return fuelLevel; // TODO: Replace this placeholder }

/** * Report the estimated number of miles remaining, in sport mode, with the current fuel. * * The estimate is based on the actual fuel efficiency achieved during the sport mode portion of * this trip, and the fuel remaining according to getFuelRemaning(). The value returned is * rounded down (truncated) to the nearest multiple of 10 miles. * * Academic Note: This method won't be called until at least some fuel has been used this trip * in sport mode. * * @return estimated sport miles remaining. */ public int getSportMilesRemaining() { // TODO: Your implementation goes here int result = findRemainingMile(fuelLevel, sportMileTrip, sportModeUsage) return result; // TODO: Replace this placeholder }

/** * Report the estimated number of miles remaining, in green mode, with the current fuel. * * The estimate is based on the actual fuel efficiency achieved during the green mode portion of * this trip, and the fuel remaining according to getFuelRemaning(). The value returned is * rounded down (truncated) to the nearest multiple of 10 miles. * * Academic Note: This method won't be called until at least some fuel has been used this trip * in green mode. * * @return estimated sport miles remaining. */ public int getGreenMilesRemaining() { // TODO: Your implementation goes here return 0; // TODO: Replace this placeholder }

/** * Report the total number of miles driven. * * This is the sum of all miles driven in any mode since this object was constructed. * * @return lifetime miles driven. */ public int getLifetimeMiles() { // TODO: Your implementation goes here return 0; // TODO: Replace this placeholder }

/** * Report the average fuel efficiency, in miles per gallon, across all trips. * * The return value is rounded down (truncated) to a multiple of 0.1 MPG. * * Academic Note: This method won't be called until at least some fuel has been used. * * @return lifetime average miles per gallon. */ public double getLifetimeMPG() { // TODO: Your implementation goes here return 0; // TODO: Replace this placeholder } // helper method to calcualate the remaining fuel public double findRemainingMile(double fuelLevel, int eachTripMileage, double fuelUsedMode) { double mpg = eachTripMileage / fuelUsedMode; int mile = (int) mpg * fuelLevel ; mile = mile * 0.1; return mile; }

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Write and customize cover letters

Answered: 1 week ago