Results 1 to 4 of 4
  1. #1
    OmegaDracoMax is offline Member
    Join Date
    Sep 2012
    Posts
    8
    Rep Power
    0

    Default 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. #2
    Zyril is offline Senior Member
    Join Date
    Oct 2011
    Location
    Sweden
    Posts
    124
    Rep Power
    0

    Default 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:
    Java Code:
    String nameOfBalloonOne = balloonOne.getName();

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,304
    Rep Power
    20

    Default 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
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    JavaAdviser is offline Member
    Join Date
    Sep 2012
    Posts
    26
    Rep Power
    0

    Default 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.

Similar Threads

  1. Array staying null
    By avoulou in forum New To Java
    Replies: 6
    Last Post: 04-17-2012, 05:27 PM
  2. how do i make the integer limited to 10
    By andnlou2678 in forum New To Java
    Replies: 1
    Last Post: 11-15-2011, 03:20 PM
  3. Integer Comparison, Outputting Largest Integer Not Working
    By killingthemonkey in forum New To Java
    Replies: 4
    Last Post: 10-16-2011, 08:59 PM
  4. Staying motivated
    By Durden in forum New To Java
    Replies: 7
    Last Post: 05-08-2011, 11:29 AM
  5. convert unsigned integer to signed integer in java?
    By diskhub in forum New To Java
    Replies: 6
    Last Post: 05-17-2010, 12:50 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •