Answer:
The answer to this question can be given as:
Class definition:
public class GasTank //define class GasTank
{
private double amount = 0; //define variable.
public void addGas(double x) //define function addGas.
{
amount=amount+x; //calculate value.
}
public void useGas(double x) //define function useGas.
{
amount=amount-x; //calculate value.
}
public double getGasLevel() //define function getGasLevel
{
return amount; //return value.
}
}
Step-by-step explanation:
The description of the above class definition can be given as:
- In the class definition first we define a class that is "GasTank". In this class we define a variable that is amount the datatype of this variable is double that is used to store real or decimal values.
- Then we define three function that is addGas(), useGas() and getGasLevel(). addGas() and useGas() function does not return any value and in both function we pass variable x as a parameter that calculate there value and the getGasLevel() function will return amount variable value.