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

    Default I need help cant figure out what's wrong

    I'm can't figure out what's wrong, im trying to get the name of the Balloon to display but I just can't get it to work...the follow is the balloon class that was given to me by my professor, after the bold line that is my work or the tester that I have to do and after the bold dashed lines that is the output, why isn't the name of the balloons showing.


    /**
    * A class to represent a hot-air balloon. Balloon objects have a name and an
    * altitude.
    */
    public class Balloon
    {
    // instance variables
    private String name ; // name of the balloon
    private int altitude; // altitude (height) of balloon in meters

    /**
    * Create a ballon object with a given name at a given altitude.
    * @param theName the name of the ballon object
    * @param theAltitude the altitude
    */
    public Balloon(String theName, int theAltitude)
    {
    name = theName ;
    // make sure altitude is not negative!
    altitude = Math.max(theAltitude,0) ;
    }

    /**
    * Ascend to a particular altitude.
    * @param newAlt the altitude to which to ascend, in meters.
    */
    public void ascendTo(int newAlt)
    {
    // ascend to new altitude only if it is greater than current altitude,

    if (newAlt > altitude)
    {
    altitude = newAlt ;
    }
    }

    /**
    * Descend to a particular altitude.
    * @param newAlt the altitude to which to descend, in meters.
    */
    public void descendTo(int newAlt)
    {
    // prevent possible crash into ground
    if (newAlt < 0) // if desired altitude is below ground level!
    {
    altitude = 0 ; // ...descend only to ground level
    }
    // otherwise, descend only if new altitude is less than current altitude
    else if (newAlt < altitude)
    {
    altitude = newAlt ;
    }
    }

    /**
    * Modify altitude by a given number of meters, up or down.
    * @param change number of meters to add to current altitude
    */
    public void adjustAltitude(int change)
    {
    // if change is negative (i.e. descending), can't go below 0 altitude
    if (change + altitude < 0) // change < 0 && abs(change) > altitude
    {
    altitude = 0 ; // ...descend only to ground level
    }
    else // safe to modify current alt by "change" meters
    {
    altitude = altitude + change ;
    }
    }

    /**
    * Get ballon name.
    * @return the name of the balloon
    */
    public String getName()
    {
    return name ;
    }

    /**
    * Get current altitude.
    * @return the altitude of the balloon
    */
    public int getAltitude()
    {
    return altitude ;
    }
    }
    // end of Balloon class definition

    _______________________________________________


    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */

    /**
    *
    * @author Lizard
    */
    public class BalloonTester {

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

    one = new String();
    two = new String();

    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 balloon is " + nameOfBalloonOne);
    System.out.println("The altitude of the balloon is " + altitudeOfBalloonOne);

    String nameOfBalloonTwo;
    double altitudeOfBalloonTwo;

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

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

    }
    }
    }

    -------------------------------------------------------------------


    run:
    The name of the balloon is
    The altitude of the balloon is 100.0
    The name of the balloon is
    The altitude of the balloon is 0.0
    BUILD SUCCESSFUL (total time: 0 seconds)

  2. #2
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    5

    Default Re: I need help cant figure out what's wrong

    one = new String();
    two = new String();
    ??
    Empty strings for the name -> no names in the output :)

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

    as an example

  3. #3
    OmegaDracoMax is offline Member
    Join Date
    Sep 2012
    Posts
    8
    Rep Power
    0

    Default Re: I need help cant figure out what's wrong

    Oh my God I feel so stupid lol, thank you so much!

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

    Default Re: I need help cant figure out what's wrong

    I seem to have hit another error how do I get my negative -100 to come out as -100 and not 0

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is online now Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,252
    Rep Power
    19

    Default Re: I need help cant figure out what's wrong

    Since you have started another thread for the new question, I'm locking this one.

    In future, don't ask the same question in more than one place. Go through the following:
    Forum Rules
    Guide For New Members
    BB Code List - Java Programming Forum

    db

    THREAD CLOSED
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. what is wrong with this? cant figure it out
    By flagrl in forum NetBeans
    Replies: 3
    Last Post: 01-27-2012, 01:10 AM
  2. i can't figure out whats wrong
    By redbrawn06 in forum New To Java
    Replies: 4
    Last Post: 10-17-2011, 09:44 PM
  3. Can't figure out what's wrong, help please.
    By Taszk in forum New To Java
    Replies: 30
    Last Post: 05-24-2011, 11:30 AM
  4. Cant figure out where went wrong.
    By leviathan in forum New To Java
    Replies: 15
    Last Post: 06-06-2010, 06:55 PM
  5. Replies: 2
    Last Post: 07-11-2008, 09:41 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
  •