Write, in JAVA code, a class named GasTank containing: An instance variable name
ID: 2246938 • Letter: W
Question
Write, in JAVA code, a class named GasTank containing:
An instance variable named amount of type double, initialized to 0.
A method named addGas that accepts a parameter of type double. The value of the amount instance variable is increased by the valueof the parameter.
A method named useGas that accepts a parameter of type double. The value of the amount instance variable is decreased by the valueof the parameter.
A method named getGasLevel that accepts no parameters. getGasLevel returns the value of the amount instance variable.
Explanation / Answer
Note: Could u plz check if u need any modifications I will do it .Thank You.
____________
GasTank.java
public class GasTank {
//Declaring instance variable
double amount=0;
public void addGas(double val)
{
amount=amount+val;
}
public void useGas(double val)
{
amount=amount-val;
}
public double getGasLevel()
{
return amount;
}
}
_______________Thank You
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.