Automobile

**parameter to the constructor which in turn passes it to the state variable, mpg. The** **constructor should also set the state variable gallons (gas in the tank) to 0. A method called** ** fillUp adds gas to the tank. Another method, takeTrip, removes gas from the tank as the** **result of driving a specified number of miles. Finally, the method reportFuel returns how** **much gas is left in the car.**
 * Create a class called Automobile in which you pass a mileage (miles per gallon)**


 * Test your Automobile class by creating a Tester class as follows:**

{ //Create a new object called myBmw. Pass the constructor an// argument of 24 miles per gallon //Use the myBmw object to call the fillup method. Pass it an argument// of 20 gallons. //Use the myBmw object to call the takeTrip method. Pass it an// argument of 100 miles. Driving 100 miles of course uses fuel and we //would now find less fuel in the tank.// //**myBmw.takeTrip(100);**// Use the myBmw object to call the reportFuel method. It returns a //double value of the amount of gas left in the tank and this is assigned// to the variable fuel_left //Print the fuel_left variable// //**System.out.println(fuel_left);**// prints gallons left, **15.833333333333332**
 * public class Tester**
 * public static void main( String args[] )**
 * Automobile myBmw = new Automobile(24);**
 * myBmw.fillUp(20);**
 * double fuel_left = myBmw.reportFuel;**
 * }**
 * }**

**Create class Automobile**

This is the constructor. This special method runs when an object is created. When the code Automobile myBmw = new Automobile(24); is executed in the Tester class, it passes 24 to the mileage parameter of this constructor.
 * public class Automobile**


 * public Automobile(double mileage)**
 * }**
 * }**
 * }**

The myBmw.fillUp(20); code in the Tester class calls this method and adds 20 gallons of gas to the gas tank by passing 20 to the gal parameter. The gal parameter is then added to the gallons state variable and the sum assigned to gallons


 * public void fillUp(double gal)**
 * }**
 * }**
 * }**

The myBmw.takeTrip(100); code in the Tester class calls this method and passes a value of 100 to the miles parameter which in turn uses it along with the state variable mpg to determine how much gas to remove from the tank as a result of driving this number of miles


 * public void takeTrip(double miles)**
 * }**
 * }**
 * }**

This method is called from the Tester class by the code myBmw.reportFuel; This method is the only one in this class that returns something. It returns the state variable gallons. It is assigned to the fuel_left variable back in the Tester class


 * public double reportFuel**
 * }**
 * }**
 * }**

//These are state variables that hold values and are// accessible to all of the methods of this class.

}
 * private ...**
 * private...**