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
Re: How do I make the integer go below 0 and become negative instead of staying at 0?
Please, post code in [CODE]-segments.
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:
Code:
String nameOfBalloonOne = balloonOne.getName();
Re: How do I make the integer go below 0 and become negative instead of staying at 0?
Please see the moderator comments on your earlier thread.
db
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
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.