public class NumberGames
{
// Keep track of the number
private double num;
// Constructor
public NumberGames(double startingNumber)
{
num = startingNumber;
}
// Returns the number
public double getNumber()
{
return num;
}
// Doubles the number
// Returns the doubled number
public double doubleNumber()
{
num *= 2;
return num;
}
// Squares the number
// Returns the squared number
public double squareNumber()
{
num *= num;
return num;
}
}
--------
public class GamesTester
{
public static void main(String[] args)
{
NumberGames game = new NumberGames(3);
// Double the number
// Print it out
// Square the number
// Print it out
// Double the number again
// Print it out
// Get the number and store the value
// Print it out to see that getNumber does
// not modify the number
}
} Exercise 2.6.6: Number Games w This class has a few methods for manipulating a number. The object has
been created for you. Call the methods indicated and print out the result of each method call. Your output
should look like this 6.0 36.0 72.0 72.0