caggh345
19.11.2019 •
Computers and Technology
Write a class named gastank containing:
an instance variable named amount of type double, initialized to 0.
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.
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.
a method named getgaslevel that accepts no parameters.
getgaslevel returns the value of the amount instance variable.
Solved
Show answers
More tips
- F Food and Cooking How to Determine Healthy, Nutritious Food for Yourself?...
- S Style and Beauty How to Get Rid of a Bruise: Tips and Tricks...
- F Food and Cooking Лечо: вкусное и простое блюдо для любой кухни...
- H Health and Medicine Relieving Swelling in Legs: Causes and Ways to Alleviate the Symptom...
Answers on questions: Computers and Technology
- C Computers and Technology what product and service type should I choose in quickbooks online if I do not want to track inventory...
- C Computers and Technology Pleasee help meeeeeeeeee I’m stuckk...
- C Computers and Technology In Python 3, write a decorator function that has the following property: 1. The name of the decorator is uppercase and takes a function as input. 2. The decorator has an inner...
- M Mathematics Find the cosine of ∠X. Write your answer in simplified, rationalized form. Do not round....
- M Mathematics Find the simple interest and the total amount after five years. Principal = 2150 rupees Annual rate of interest 11% Total interest rupees Total amount rupees...
- M Mathematics PLS HELP ME I NEED THIS FASTTT ON SHOW ALL YOUR WORK List the values for a, b and c in the following quadratic equation. 3x^2 + 6x = 7 Use your preferred method to solve the following...
- P Physics La aceleración debida a la gravedad en la Luna es de aproximadamente 1,6 m / s2. ¿Cuánta más fuerza gravitacional experimenta un objeto de 80 kg en la Tierra que en la Luna? Acceleration...
- M Mathematics I WILL GIVE YOU ALL MY POINTS IF YOU GIVE ME THE FUNCTION AND JUSTIFICATION FOR THE 2 QUESTION IN THIS PICTURE PLEASE HELP...
- A Arts 14 Type the correct answer in the box. Spell all words correctly. In which model does the color black form the key color? The color black forms the key color in the model. model....
- M Mathematics NEED HELP QUICK CAN SOMEONE PLEASE HELP WITH THIS...
Ответ:
The answer to this question can be given as:
Class definition:
public class GasTank //define class GasTank
{
private double amount = 0; //define variable.
public void addGas(double x) //define function addGas.
{
amount=amount+x; //calculate value.
}
public void useGas(double x) //define function useGas.
{
amount=amount-x; //calculate value.
}
public double getGasLevel() //define function getGasLevel
{
return amount; //return value.
}
}
Explanation:
The description of the above class definition can be given as:
In the class definition first we define a class that is "GasTank". In this class we define a variable that is amount the datatype of this variable is double that is used to store real or decimal values.Then we define three function that is addGas(), useGas() and getGasLevel(). addGas() and useGas() function does not return any value and in both function we pass variable x as a parameter that calculate there value and the getGasLevel() function will return amount variable value.Ответ:
//. Program is written in Java Programming Language
// Comments are used for explanatory purpose
// Program starts here
// import required libraries
import java.swing.JApplet;
import java.awt.*;
// Declare class as
public class DrawGraphics extends JApplet
{
//.Assume the following values for width, height and area of the shape
final int area= 150 ;
final int width = 100, height = 50;
{
//Draw a Rectangle around the applet's display area starting from 5,15
g.drawRect( 5,15, area-1, area-1 );
//Draw the current string inside the rectangle
g.drawRect( area/2 - width/2 , area/2 - height/2, width, height );
}
}