• Register
Welcome to Kodlogs, programming questions and answer website.
0 votes
6 views

Problem:

A data member named amount of type double .

A constructor that no parameters . The constructor initializes the data member amount to 0.

A function named addGas that accepts a parameter of type double . The value of the amount instance variable is increased by the value of the parameter .

A function named useGas that accepts a parameter of type double . The value of the amount data member is decreased by the value of the parameter .

A function named getGasLevel that accepts no parameters . getGasLevel returns the value of the amount data member.

I am getting error, can anyone help please.

by (750 points)  
edited by

1 Answer

0 votes

Solution:

public class GasTank {

private double amount = 0;

private double capacity;

public GasTank(double i) {

capacity = i;

}

public void addGas(double i) { amount += i; if(amount > capacity) amount = capacity; / amount = amount < capacity ? amount+i : capacity;/ }

public void useGas(double i) { amount = amount < 0 ? 0 : amount - i; }

public boolean isEmpty() { return amount < 0.1 ? true : false; }

public boolean isFull() { return amount > (capacity-0.1) ? true : false; }

public double getGasLevel() { return amount; }

public double fillUp() { double blah = capacity - amount; amount = capacity; return blah; }

}

by (3.5k points)  
...