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
I need the answer to the below question *ASAP*
Mashutka [201]

2 4 9

Explanation:

Basically what I thought was the way was, since 2 is first, then its 1, then since 4 is second, it's added second, lastly to get the last oneI added them all and got 9 so that's third.

4 0
3 years ago
Read 2 more answers
Write a program that allows the user to enter a start time and a future time. Include a function named compute Difference that t
Aleonysh [2.5K]

Step 1

Following is the c++ program:

Variables used:

startHours, startMins are used to store the starting time of time machine.

futureHours, futureMins are used to store the future time of time machine.

xAM variable is used to store meridiem of start and future time.

isSAM is boolean variable that is true if starting time is AM.

isFAM is boolean variable that is true if future time is AM.

 

Functions:

main() is used to call computeDifference() function that will calculate the difference between the start and future time.

computeDifference() takes as input six variables from the user and then apply the following logic to compute the difference between the start and future time:

If Meridien of both start and future time are the same, then simply subtract the start time from the future time.

Difference = future minutes – start minutes

If Meridien of both start and future time are different, then apply the following formula to calculate difference:

Difference = (12 * 60 – start minutes) + future minutes

Step 2

Program :

#include <iostream> //header file for input and output

 

using namespace std;

//calculate the time difference(in minutes) between start time and future time.

int computeDifference(int startHours, int startMins, bool isSAM, int futureHours, int futureMins, bool isFAM) {

 int difference = 0; //to store difference

 startMins = startHours * 60 + startMins; //converting in minutes.

 futureMins = futureHours * 60 + futureMins; //converting in minutes.

 //applying formula for difference.

 if (isSAM == isFAM) {

   difference = futureMins - startMins;

 } else if (isSAM == true && isFAM == false) {

   difference = (12 * 60 - startMins) + futureMins;

 }

}

int main() {

 int startHours, startMins; //it will store start time

 int futureHours, futureMins; //it will store future time.

 string xAM; //it will store meridiem.

 bool isSAM; //it will be true if start time is AM.

 bool isFAM; //it will be true if future time is in AM.

 int difference = 0; //it will store difference.

 cout << "Enter start time of time machine as 'HH MM AM/PM': "; //take input from

7 0
3 years ago
Commands under menu bar in a computer
Brilliant_brown [7]

Answer:

File, Edit, and View

Explanation:

These are the standard ones that come with the software.

3 0
3 years ago
There are three levels of FDA approval for medical devices, with Level 1 being advanced technological products such as pacemaker
FromTheMoon [43]

<em>The answer is FALSE. </em>

<em>3 Levels of FDA's are: </em>

  • <em>Class 1 - these are devices that contains low risk to the user or patient. Examples: bandages, bedpans, stethoscopes.  </em>
  • <em>Class 2 - devices that has moderate risk to the user such as wheelchairs. </em>
  • <em>Class 3 - devices that implements and support life forms. These can be either inside (implanted) or not. Examples of this are: pacemakers and implants. </em>

<em />

5 0
3 years ago
Which group and tab do you need to be in to separate text into two columns? Paragraph group and Insert tab Page Layout group and
WARRIOR [948]

Answer: Page setup group and page layout tab

Explanation:

:)

7 0
3 years ago
Other questions:
  • Food is shipped thousands of miles throughout our country using various types of transportation such as trucks, planes, and boat
    10·1 answer
  • Each server on a network that needs to act as a web server needs an application layer software package called a (n) ____________
    15·1 answer
  • If you write a toString method to display the contents of an object, object1, for a class, Class1, then the following two statem
    14·1 answer
  • What type of traffic always goes to all devices in a subnet?
    10·1 answer
  • A __________ network is good for connecting computers over boundaries.
    6·2 answers
  • When a user utilizes another computer to communicate with a third party, with the result that the third party cannot recognize t
    8·1 answer
  • What is the system that consists of nonproprietary hardware and software based on publicly known standards that allow third part
    13·1 answer
  • Write a program that prompts the user to enter a series of numbers between 0 and 10 asintegers. The user will enter all numbers
    6·1 answer
  • What should you do first when designing a program?
    5·2 answers
  • What happens on your screen when you click on the eyedropper tool in Scratch? The background of your scene will become transpare
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!