Menu
support@nursinghomework.org
+1 714-215-3097

(Solved) : Write Class Named Gastank Containing Instance Variable Named Amount Type Double Initialize Q35556371

Write a class named GasTank containing:

  • An instance variable named amount of type double, initializedto 0.
  • An instance variable named capacity of type double.
  • A constructor that accepts a parameter of type double. Thevalue of the parameter is used to initialize the value ofcapacity.
  • 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. However, if the value of amount is increasedbeyond the value of capacity, amount is set to capacity.
  • 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. However, if the value of amount is decreasedbelow 0, amount is set to 0.
  • A method named isEmpty that accepts no parameters. isEmptyreturns a boolean value: true if the value of amount is less than0.1, and false otherwise.
  • A method named isFull that accepts no parameters. isFullreturns a boolean value: true if the value of amount is greaterthan capacity-0.1, and false otherwise.
  • A method named getGasLevel that accepts no parameters.getGasLevel returns the value of the amount instance variable.
  • A method named fillUp that accepts no parameters. fillUpincreases amount to capacity and returns the difference between thevalue of capacity and the original value of amount (that is, theamount of gas that is needed to fill the tank to capacity).

Leave a Reply

Your email address will not be published. Required fields are marked *