Main Method:
public class Driver { public static void main(String[] args) { double distance = 400.48; double fuel = 21.4; AutoTrip myTrip = new AutoTrip(distance, fuel); System.out.print("My car traveled " + myTrip.getDistance() + " miles "); System.out.println("on " + myTrip.getFuel() + " gallons of gasoline."); double mileage = myTrip.getMPG(); // get miles per gallon System.out.println("My mileage was " + mileage + "."); } }
Suppose to Produce:
My car traveled 400.48 miles on 21.4 gallons of gasoline.
My mileage was 18.714018691588787.
What is wrong with my output?
private double miles; private double gallons; private double mileage; public AutoTrip(double distance, double fuel, double MPG){ distance = miles; fuel = gallons; MPG = mileage; } public double getDistance() {return miles;} public double getFuel() {return gallons;} public double getMPG() {return mileage;}