The code in this example demonstrates how to write a class named Acc2 containing two data members. The class contains a data member named sum, which is an integer, and a method named getSum, which accepts a single integer parameter as the first parameter. The method gets the sum and returns it. You can call getSum to get the sum. This code shows you how to write an ACC2 class.
The GasTank class contains two instance variables. The first one is of type double, and is initialized to zero. The other two are static and accept one double parameter. The add method takes an integer parameter, and sets the value of maxTime to the value of the parameter. The other method is called getGasLevel and returns the amount of gas. The last method is named getGasLevel, and it returns the amount of gas.
The GasTank class contains a single instance variable, amount. It is initialized to 0. The add method accepts a double parameter, and useGas methods decrease the value of the amount. The getGasLevel method receives a boolean parameter. If the amount of gas in the Tank is below the value of the parameter, the gas level is zero.
The GasTank class contains one instance variable, amount, of type double. It is initialized to zero. It has methods that increase and decrease the amount. The addGas method accepts a double parameter and increases the value of timeLeft by 30 if the parameter is greater than maxTime. The useGas method accepts no parameters. The getGasLevel method gets the value of the number.
The class GasTank object has a single instance variable, amount. The value of timeLeft is a double. The addGas method accepts a double parameter and increments the value of the amount by 0. The useGas method subtracts the value of gas from the Tank and returns it as a boolean. Once this method is complete, the acc2 container is ready to be used in the application.
The GasTank class has a single instance variable of type Double, which is initialized to 0. Its constructor accepts a double parameter to initialize the maxTimeinstance variable. The add method raises the value of timeLeft by thirty if the amount of gas is greater than the parameter. Finally, the getGasLevel method returns the current level of gas. This is the second example of a GasTank.
A GasTank class has two instance variables: timeLeft and maxTime. They are both of type double and should be initialized to zero. The addGas and useGas methods both take an integer parameter as its first argument. The add method is the only way to set the amount of gas by using this API. If the value of gas is higher than the minimum value, the method will increase the amount of gas by thirty.
The GasTank class contains two instance variables: timeLeft and maxTime. Both of these are of type double and should be initialized to zero. The constructor accepts a single parameter of type int. The value of this parameter initializes the maxTimeinstance. The add method returns the amount of gas in the tank. The getGasLevel() method is static and takes no parameters.
The GasTank class contains an instance variable of type double and initialized to zero. The addGas and useGas methods take an integer as a parameter. Then, they call the getGasLevel method to return the current amount of gas. Once the GasTank has been created, it’s time to test it. Several other methods are necessary to implement the object. The name of the class and its implementation are described in the following sections.