Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

...using java...Thank you for your help! This program defines an Odometer dass t

ID: 3616642 • Letter: #

Question

...using java...Thank you for your help! This program defines an Odometer dass to track fuel and mileage. It stores the miles driven and fuel efficiency and includes A function to calculate the number of gallons of gasoline consumed. Make sure instance variables are private Define a dass called Odometer that will be used to track fuel and mileage for an automobile. The dass should have instance variables to track the miles driven and the fuel efficiency of tie vehicle in miles per gallon. Include a mutator method to reset the odometer to zero miles, a mutator method to set the fuel efficiency, a mutator method that accepts miles driven for a trip and adds it to the odometer's total, and an accessor method that returns the number of gallons of gasoline that the vehicle has consumed since foe odometer was last reset.

Explanation / Answer

please rate - thanks How's this? Class class Odometer { private int miles; private double mpg; public Odometer() { miles=0; mpg=0; } public double getEfficiency() { return miles/mpg;        //accessor to return gallons used } public void resetMiles()      //mutator toreset odometer {miles=0; } public void resetMPG(double num)   //mutator to set fuelefficiency {mpg=num; } public void addMiles(int num)     //mutator toadd miles to the trip {miles+=num; } } Test program public static void main(String[] args) {Odometer myCar = new Odometer(); myCar.resetMPG(30);        //set miles per gallon myCar.addMiles(50);        //go on a trip myCar.addMiles(200); System.out.println("The cars efficiency this trip was"+myCar.getEfficiency()); myCar.resetMiles();         //reset miles myCar.resetMPG(20);         //set miles per gallon myCar.addMiles(50);          //go on a trip myCar.addMiles(75); myCar.addMiles(15); System.out.println("The cars efficiency this trip was"+myCar.getEfficiency()); } }