# Thread: How do I make the integer go below 0 and become negative instead of staying at 0?

1. Member
Join Date
Sep 2012
Posts
8
Rep Power
0

## How do I make the integer go below 0 and become negative instead of staying at 0?

Instead of having 0 I want to have -100 as my output, how do I get this to work.

public class BalloonTester {

public static void main (String[] args)
{
String one;
String two;

one = "One";
two = "Two";

Balloon balloonOne = new Balloon(one,100);

Balloon balloonTwo = new Balloon(two,(-100));

String nameOfBalloonOne;
double altitudeOfBalloonOne;

nameOfBalloonOne = balloonOne.getName();
altitudeOfBalloonOne = balloonOne.getAltitude();

System.out.println("The name of the first balloon is " + nameOfBalloonOne +
" and the altitude of the balloon is " + altitudeOfBalloonOne);

String nameOfBalloonTwo;
double altitudeOfBalloonTwo;

nameOfBalloonTwo = balloonTwo.getName();
altitudeOfBalloonTwo = balloonTwo.getAltitude();

System.out.println("The name of the second balloon is " + nameOfBalloonTwo +
" and the altitude of the balloon is " + altitudeOfBalloonTwo);

__________________________________________________ _______

The name of the first balloon is One and the altitude of the balloon is 100.0
The name of the second balloon is Two and the altitude of the balloon is 0.0

2. Senior Member
Join Date
Oct 2011
Location
Sweden
Posts
124
Rep Power
0

## Re: How do I make the integer go below 0 and become negative instead of staying at 0?

Also, post relevant code, in this case the Balloon class.

Third, why are you declaring the variables on separate lines instead of in one line?
A more efficient way is this:
Java Code:
`String nameOfBalloonOne = balloonOne.getName();`

db

4. Member
Join Date
Sep 2012
Posts
26
Rep Power
0

## Re: How do I make the integer go below 0 and become negative instead of staying at 0?

If you look in the constructor of the Balloon class there is the line
Java Code:
`altitude = Math.max(theAltitude, 0);`
which makes sure altitude is not negative. Just like the comment above it says.

A similar thing is in the adjustAltitude() method but that's not used in the Tester class.
Last edited by JavaAdviser; 09-13-2012 at 11:26 PM.