1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Anvisha [2.4K]
3 years ago
13

Write a class named GasTank containing: An instance variable named amount of type double, initialized to 0. An instance variable

named capacity of type double. A constructor that accepts a parameter of type double. The value of the parameter is used to initialize the value of capacity. A method named addGas that accepts a parameter of type double. The value of the amount instance variable is increased by the value of the parameter. However, if the value of amount is increased beyond 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 value of the parameter. However, if the value of amount is decreased below 0, amount is set to 0. A method named isEmpty that accepts no parameters. isEmpty returns a boolean value: true if the value of amount is less than 0.1, and false otherwise. A method named isFull that accepts no parameters. isFull returns a boolean value: true if the value of amount is greater than 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. fillUp increases amount to capacity and returns the difference between the value of capacity and the original value of amount (that is, the amount of gas that is needed to fill the tank to capacity).
Computers and Technology
1 answer:
telo118 [61]3 years ago
5 0

Answer:

The class GasTank is defined below

All the steps are briefed in comments

public class GasTank {

// instance variable initialization

private double amount = 0;

//declaring instance variable capacitance

private double capacity;

//constructor having parameter of type double

public GasTank(double i)

{

capacity = i;

}

// addGas method for increasing gas quantity.

public void addGas(double i)

//quantity of gas increased is added to the existing amount. If it becomes more than total capacity, amount is set to capacity

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

//useGas method having parameter of type double

public void useGas(double i)

//the parameter given is deducted from 0 and if results less than 0, remains equal to 0

{ amount = amount < 0 ? 0 : amount - i; }

//method isEmpty

public boolean isEmpty()

//Returns true if volume is less than 0.1 else false

{ return amount < 0.1 ? true : false; }

//method isFull

public boolean isFull()

//returns true if the value of amount is greater than  0.1 else false.

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

//method getGasLeve

public double getGasLevel()

//Returns the value of amount instance variable

{ return amount; }

//method fillUp

public double fillUp()

//returns the difference between the capacity and the amount

{ double blah = capacity - amount; amount = capacity; return blah; }

}

You might be interested in
What is block chain?
LuckyWell [14K]

Answer:

Block Chain is a system of recording information that makes it difficult or impossible to change, hack, or cheat the system.

A blockchain is essentially a digital ledger of transactions that is duplicated and distributed across the entire network of computer systems on the blockchain.

Hope this helps.

x

6 0
2 years ago
Read 2 more answers
What does a blinking yelow light mean on a phillips sonicare toothbrush
babunello [35]

Answer:

it means that you need to charge it or change the batteries depending on what kind you have

3 0
2 years ago
How do you recognize substances that have gone through physical or chemical changes?
Leviafan [203]
Normally  you can't.   You cannot tell if water has been frozen and then thawed.
7 0
2 years ago
Read 2 more answers
In short and brave what is technology?
emmainna [20.7K]

Answer:

technology is a whole means to provide goods needed for the survival and comfort of human life

8 0
3 years ago
Read 2 more answers
How do you restore deleted notpad++ file?
Natasha2012 [34]
Check your trash can, if that doesnt work then I would say its lost.
3 0
2 years ago
Other questions:
  • In what ways us cyberspace is real? list at least 3 examples to support your response .
    9·1 answer
  • How to search for the largest files on my computer vista?
    5·1 answer
  • Why do most laptops have LCD rather than OLED displays, which are found on mobile devices?
    9·1 answer
  • !WILL MARK BRAINLIEST!
    8·1 answer
  • What layer of the OSI model describes how data between applications is synced and recovered if messages don't arrive intact at t
    12·1 answer
  • Face book suggests Friends for users based on their
    13·1 answer
  • Unconformities develop when new sedimentary layers accumulate atop old, eroded layers, resulting in a geologic hiatus. Which of
    9·1 answer
  • Classroom content transaction <br> examples use of IT
    8·1 answer
  • Samantha is part of a project management team working on the initiation phase of a project. What is her team expected to do in t
    5·2 answers
  • Choosing a per_formatted presentation that already has a design and the slots is called choosing What​
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!