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
File
Degger [83]

Explanation:

formula should add cells D3:07.

Empanadas & More

1

In cell D9 create a formula that calculates the total after a 10% disco

you need help understanding how to take a percentage off of a total

LINE TOTAL

2 MENU ITEM

3 Empanadas: Buffalo Chicken

4 Empanadas: Braised Short Rib

5 Empanadas: Fig and Goat Cheese

6 Sides: Black beans and rice

7

UNIT PRICE

$2.98

$2.98

$3.75

$1.98

QUANTITY

20

30

25

40

TAX

8

TOTAL

6 0
3 years ago
Please Answer Quickly.<br> Match the item on the left with the reason that it is false on the right.
Varvara68 [4.7K]

Answer:

me desculpe mais eu preciso de pontos para ajudr meu irmão autista

5 0
2 years ago
“When using a public computer for browsing the Internet, try to use for 1.________ transactions. Also, use 2.__________ browsing
Tamiku [17]

option 2 is c

option 1is B

3 0
3 years ago
Read 2 more answers
The domain in an email message tells you the
bezimeni [28]
The question is asking to choose among the following choices that state what would the domain in an email represents, base on my research, I would say that the answer would be letter B. location of the destination. I hope you are satisfied with my answer and feel free to ask for more 
8 0
3 years ago
Which step of the design process is the company currently engaged
RideAnS [48]

The answer is pictures

8 0
2 years ago
Other questions:
  • 10.Find the first ICMP Echo Request message that was sent by your computer after you changed the Packet Size in pingplotter to b
    8·1 answer
  • How do you change exposure to allow for greater DoF
    10·1 answer
  • What type of printer heats toner to adhere it to the paper? inkjet . impact. 3D. laser.
    6·1 answer
  • Give an example of an app, website, or a game that used addictive design. Describe three features of addictive design it uses.
    11·2 answers
  • How much is a stock supra 1998​
    15·1 answer
  • Por favor alguem poderia me falar qual PC e melhor: Computador Gamer Fox PC FPS Intel Core i5 8GB (GeForce GTX 1050Ti 4GB GDDR5)
    15·1 answer
  • How to be fluent in computer
    10·2 answers
  • Some printers spray ink, while others use heat or lasers to create images.
    14·2 answers
  • Which statement best describes the problem statement below?
    6·1 answer
  • Explain how communication has helped to the staff in organization to reach their maximum delivery of service with efficience and
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!