Question: Java code 2)- Car Write a class named Car that has the following fields: Make:a String that contains the name of the car's manufacturer Model:a
Java code 2)- Car Write a class named Car that has the following fields: Make:a String that contains the name of the car's manufacturer Model:a String that contains the model of the car gasMileage a double that contains the miles that the car can travel on a gallon of gas totalDistance:a double that contains the total distance travelled by the car totalGasUsed: a double that contains the total amount of gas used by the car The class has a method named drive that accepts an int parameter that contains a distance travelled. Every time drive is called, totalDistance is updated, and totalGasUsed is computed as the quotient of totalDistance divided by gasMileage. Write a driver class that creates several cars, then calls the drive method of each car several times with different distances. Then print the totalDistance and totalGasUsed for each car
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
