Answer:
Step-by-step explanation:
The following code is written in Java and contains each of the methods requested working and performing the requested functions.
class GasTank {
double amount = 0;
double capacity;
public void GasTank(double capacity) {
this.capacity = capacity;
}
public void addGas(double gasAmount) {
this.amount += gasAmount;
if (this.amount > this.capacity) {
this.amount = this.capacity;
}
}
public void useGas(double useGas) {
this.amount -= useGas;
if (this.amount < 0) {
this.amount = 0;
}
}
public boolean isEmpty() {
if (this.amount < 0.1) {
return true;
} else {
return false;
}
}
public boolean isFull() {
if (this.amount > (this.capacity - 0.1)) {
return true;
} else {
return false;
}
}
public double getGasLevel() {
return this.amount;
}
}