Create a project called Mileage . In it, create a class Car with the following properties. A car has a certain fuelEfficiency (measured in miles/gallon) and a certain amount of fuel ( fuelLevel ) in...


Create a project calledMileage. In it, create a classCar with the following properties. A car has a certainfuelEfficiency (measured in miles/gallon) and a certain amount of fuel (fuelLevel) in the gas tank.


Write a constructor for the class that accepts the efficiency value, and sets the initial fuel level to 0.


Write the following methods:



  • drive - simulates driving the car for a certain distance, reducing the fuel level in the gas tank. The method should have a parameter for miles - how many miles were driven. It does not return anything.

  • getGasLevel, to return the current fuel level

  • addGas - to add gas to the car. It should have a parameter of how many gallons of gas are being added.


Create a car object in main and test your class. Here is a sample run of the program:


Car­ myCar1=­new­Car(30);­   //­ 30 miles per gallon

myCar.addGas(20);­   //­ Add 20 gallons

myCar.drive(100);­   //­ Drive 100 miles
System.out.println(myCar.getGasLevel());   //­Print fuel remaining


Jun 03, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here