Respuesta :
Answer:
See explaination
Explanation:
class Car
{
private double drdist;
private double fuel;
private double mpg;
public Car(double m)
{
mpg = m;
fuel = 0;
}
public void addGas(double add)
{
fuel = fuel + add;
}
public void drive(double d)
{
drdist = drdist + d;
mpg = fuel * mpg / d;
}
public double getGasLevel()
{
return fuel;
}
}
public class Carfuel{
public static void main(String []args){
Car myHybrid = new Car(50); //50 miles per gallon
myHybrid.addGas(20); // Tank 20 gallons
myHybrid.drive(100); // Drive 100 miles
System.out.println(myHybrid.getGasLevel()); // Print fuel remaining.
}
}
Classes are simply templates, with which methods are created.
The class Car and other methods written in Java, where comments are used to explain each line is as follows:
//This defines the Car class
class Car{
//The next three lines defines the variables
private double drdist;
private double fuel;
private double mpg;
//This creates the car method
public Car(double m){
//This initializes the mileage
mpg = m;
//This initializes the amount of fuel to 0
fuel = 0;
}
//This creates the addGas method
public void addGas(double add){
//This increases the amount of fuel
fuel += add;
}
//This creates the drive method
public void drive(double d){
//This calculates the distance traveled
drdist += d;
//This calculates the mileage
mpg = fuel * mpg / d
}
//This creates the getGasLevel method
public double getGasLevel(){
//This returns the amount of fuel
return fuel;
}
}
//This main class begins here
public class Carfuel{
public static void main(String []args){
Car myHybrid = new Car(50); //50 miles per gallon
myHybrid.addGas(20); // Tank 20 gallons
myHybrid.drive(100); // Drive 100 miles
System.out.println(myHybrid.getGasLevel()); // Print fuel remaining
}
}
Read more about Java class at:
https://brainly.com/question/10124207