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
In vehicles equipped with ABS, the driver's foot must remain firmly on the _________ to activate the ABS.
DanielleElmas [232]
<span>The driver’s foot must remain firmly on the brake pedal to activate the ABS.

An Anti-lock Brake system (ABS) is an effective braking system if used correctly. It simply keeps the foundation braking systems from locking up. It allows the driver to maintain directional stability and in some cases, reduces stopping distances during emergency situations when a driver slams the brake.
The foot of those drivers in vehicles equipped with ABS should remain firmly on the brake pedal, allowing this system to automatically kick in. In case of a slippery road or a panic stop, an Anti-lock Brake system prevents wheel lock up and helps your vehicle maintain a straight line</span>
3 0
3 years ago
Read 2 more answers
.in the array based list implementation of the ADT what is the worst case time efficiency of the getEntry method?
kenny6666 [7]

Answer:

c.O(n)

Explanation:

In the array based list implementation of the ADT the worst case time complexity of the getEntry method is O(n).In the worst case it has to travel upto n elements then it has to do the operation.In doing so  the time complexity will come out to be O(n).So we conclude that the answer to this question is O(n).

5 0
3 years ago
.How does kinetic energy affect the stopping distance of a vehicle traveling at 30 mph compared to the same vehicle traveling at
Virty [35]
The overall kinetic energy of the 60mph car is greater than the overall kinetic energy of the 30mph car. Because of this, it takes a greater force to stop the faster car because it has greater amount of kinetic energy (aka the amount of force needed to overcome the momentum of the faster car is larger).
4 0
3 years ago
Kristi, an event planner, wants to store caterers’ names and contact information in an organized manner. Kristi will MOST LIKELY
bixtya [17]

Answer:

Publisher Program

Explanation:

5 0
3 years ago
What is looping in QBASIC​
Elden [556K]

A looping is a set of instructions which is repeated a certain number of times until a condition is met. hlo dai k xa halkhabar

3 0
3 years ago
Other questions:
  • type the correct answer in the Box spell the words correctly Caleb is working on a simple logic base program to stimulate the ga
    5·2 answers
  • How many bits are required to address a 1mx8 main memory if main memory is byte addressable?
    6·1 answer
  • Each computer or device on a network is called a(n) ______.
    7·1 answer
  • Is 5g harmful to the body ?
    9·2 answers
  • Which of the following is not a hazard a driver might encounter?
    5·1 answer
  • Write an algorithm that accepts two numbers,
    7·1 answer
  • Exercise#3: Write a program that performs the following: Declare a two arrays called arrayA and arrayB that holds integer and th
    14·2 answers
  • Ano ang ibig sabihin ng tanka<br>​
    5·1 answer
  • Read each of the following statements about Computer Science and explain why you think that statement is true.
    9·1 answer
  • Which web-authoring software enables users to create sophisticated web pages without knowing any html code?.
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!