Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 10 of 10

Thread: Can't create Balloon Objects.

  1. #1
    Junior Member
    Join Date
    Jan 2014
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Can't create Balloon Objects.

    Hello, this is my first code assignment. Our instructor gave us a list of steps to complete after creating a Balloon, but I can't get past just creating it. Search results have brought up other Balloon thread, however I couldn't find a topic about issues just creating the balloon.

     
    package myprojects;
     
    public class BalloonTester 
    {   
    public static void main(String[] args)
    {
     
     
    Balloon redBalloon = new Balloon("Red Balloon", 100);
     
    int Altitude ;
    String Name ; 
     
    Name = redBalloon.getName() ; 
    Altitude = redBalloon.getAltitude() ;
    System.out.println(Name);
    System.out.println(Altitude);
     
     
    }
    }


    When I compile and run it generates the following in the output.



    ant -f D:\\Users\\PLACEHOLDER\\Documents\\School\\Program ming\\MyProjects -Dnb.internal.action.name=run run
    init:
    Deleting: D:\Users\PLACEHOLDER\Documents\School\Programming\ MyProjects\build\built-jar.properties
    deps-jar:
    Updating property file: D:\Users\PLACEHOLDER\Documents\School\Programming\ MyProjects\build\built-jar.properties
    Compiling 2 source files to D:\Users\PLACEHOLDER\Documents\School\Programming\ MyProjects\build\classes
    D:\Users\PLACEHOLDER\Documents\School\Programming\ MyProjects\src\myprojects\BalloonTester.java:21: error: cannot find symbol
    Balloon redBalloon = new Balloon("Red Balloon", 100);
    symbol: class Balloon
    location: class BalloonTester
    D:\Users\Davi\Documents\School\Programming\MyProje cts\src\myprojects\BalloonTester.java:21: error: cannot find symbol
    Balloon redBalloon = new Balloon("Red Balloon", 100);
    symbol: class Balloon
    location: class BalloonTester
    2 errors
    D:\Users\PLACEHOLDER\Documents\School\Programming\ MyProjects\nbproject\build-impl.xml:920: The following error occurred while executing this line:
    D:\Users\PLACEHOLDER\Documents\School\Programming\ MyProjects\nbproject\build-impl.xml:260: Compile failed; see the compiler error output for details.
    BUILD FAILED (total time: 0 seconds)

    Edit: The following is the Balloon class, our instructions were not the edit this class in anyway.
    /**
     * 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


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,580
    Thanks
    49
    Thanked 2,233 Times in 2,205 Posts

    Default Re: Can't create Balloon Objects.

    BalloonTester.java:21: error: cannot find symbol
    Balloon redBalloon = new Balloon("Red Balloon", 100);
    symbol: class Balloon
    Where is the Balloon class defined? The compiler can not find its definition.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Jan 2014
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Can't create Balloon Objects.

    My apologies, the Balloon.Java has been added to the OP. Instructions were to leave this class unedited.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,580
    Thanks
    49
    Thanked 2,233 Times in 2,205 Posts

    Default Re: Can't create Balloon Objects.

    Where is the Balloon.class file when you try to compile BalloonTester.java? The Balloon.class file needs to be on the classpath so that the javac compiler can find it.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Jan 2014
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Can't create Balloon Objects.

    Thanks for checking my post out.

    3LDTrj7.jpg

    ACMEUsQ.jpg

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,580
    Thanks
    49
    Thanked 2,233 Times in 2,205 Posts

    Default Re: Can't create Balloon Objects.

    Are both java source files in the same folder?
    What command is used to compile the programs?

    Can you use the command prompt window and the javac command to compile the programs?
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Jan 2014
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Can't create Balloon Objects.

    Both are in the same java folder.

    File Directory.jpg

    I am using NetBean IDE 7.4.

    Can you use the command prompt window and the javac command to compile the programs?
    I am sorry, I would be happy to, but I am unaware exactly how.

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,580
    Thanks
    49
    Thanked 2,233 Times in 2,205 Posts

    Default Re: Can't create Balloon Objects.

    It looks like you are having a problem setting up the IDE. I don't know anything about your IDE.
    Take a look at the tutorial: Lesson: The "Hello World!" Application (The Java™ Tutorials > Getting Started)
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,290
    My Mood
    Mellow
    Thanks
    191
    Thanked 668 Times in 655 Posts

    Default Re: Can't create Balloon Objects.

    From what you posted, BalloonTester is in package myprojects while Balloon is not. They should be in the same package, so if it's not there already, adding

    package myprojects;

    to Balloon may fix the problem. Your IDE should be complaining loudly about this problem, if it exists, so perhaps it's not a problem.

  10. #10
    Junior Member
    Join Date
    Jan 2014
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Can't create Balloon Objects.

    I am not sure where along the way I created the problem, but deleting the project folder and starting from scratch fixed the problem. Thank you guys for your help.

Similar Threads

  1. Can't create Balloon Objects.
    By Lifeleaf in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 26th, 2014, 01:20 PM
  2. How do you create Date objects?
    By ojonugwa in forum Java Theory & Questions
    Replies: 4
    Last Post: August 27th, 2013, 01:32 PM
  3. how to create multiple objects
    By dominco in forum What's Wrong With My Code?
    Replies: 8
    Last Post: November 6th, 2012, 07:12 AM
  4. Trying to create an array of stacks that contain objects
    By jadeclan in forum Collections and Generics
    Replies: 15
    Last Post: October 6th, 2012, 03:30 PM
  5. Create Objects on Demand?
    By Programmierer in forum Object Oriented Programming
    Replies: 5
    Last Post: July 7th, 2010, 01:13 PM

Tags for this Thread