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 11 of 11

Thread: Help With BalloonTester

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

    Default Help With BalloonTester

    I am supposed to write a Tester to get the current volume of a balloon that starts with a radius of 0 after it is inflated.

    This is the balloon:

    public class Balloon
    {
     
    	private double savedRadius;//instance variable
     
    	/**constructor!!
          Constructs a balloon with a radius
       */
       public Balloon(double radius)
    	{
    	savedRadius = radius;
    }
     
    	//doubles the radius of the balloon
    	public void inflate(double radius)
       {
          savedRadius = savedRadius + radius; //returning total, accumilating 
          }
     
    		/**
          Gets the volume*/
     
    		 public double getVolume()
     
       {
          double volume = (1.33 * 3.14 * savedRadius * savedRadius * savedRadius);
    		return volume;
       }
       }

    This is what I have so far for the BalloonTester. I have tried multiple different things and I keep getting errors, I am at my wits end.

    public class BalloonTester
    {
       /**
     
       */
       public static void main(String[] args)
     
       {
     
          Balloon newBalloon = new Balloon(0);
     
          System.out.println("Current volume of the ballon: "+newBalloon.getVolume());
     
    	 }
    }

    I am not asking for it to be done for me, I just need to know where to start as this is getting on my nerves.


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 697 Times in 679 Posts

    Default Re: Help With BalloonTester

    Welcome to the forum! Thanks for taking the time to learn how to post code correctly. If you haven't already, please read this topic to learn other useful info for new members.

    I have tried multiple different things and I keep getting errors
    Post code with the full text of its corresponding errors so we know what to help you with.

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

    Default Re: Help With BalloonTester

    Quote Originally Posted by GregBrannon View Post
    Welcome to the forum! Thanks for taking the time to learn how to post code correctly. If you haven't already, please read this topic to learn other useful info for new members.



    Post code with the full text of its corresponding errors so we know what to help you with.
    Well one of the things I tried was ..

    public class BalloonTester
    {
       /**
     
       */
       public static void main(String[] args)
     
       {
     
          Balloon newBalloon = new Balloon(0);
          double radius;
          double inflate;
          newBalloon.inflate();
     
     
          System.out.println("Current volume of the ballon: "+newBalloon.getVolume());
     
    	 }
    }

    the error is :
    BalloonTester.java:21: error: method inflate in class Balloon cannot be applied to given types;
    newBalloon.inflate();
    ^
    required: double
    found: no arguments
    reason: actual and formal argument lists differ in length
    1 error
    I know that isn't enough, I am really lost for some reason.

  4. #4
    Senior Member
    Join Date
    Jul 2013
    Location
    Europe
    Posts
    666
    Thanks
    0
    Thanked 121 Times in 105 Posts

    Default Re: Help With BalloonTester

    The error message is quite clear:
    required: double
    found: no arguments
    The method you tried to call requires a double argument and you were giving it no arguments.
    Give the method a double as an argument and this error will be gone.

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

    Default Re: Help With BalloonTester

    I tried this:
     
    public class BalloonTester
    {
       /**
     
       */
       public static void main(String[] args)
     
       {
     
          Balloon newBalloon = new Balloon(0);
          double inflate;
          double radius;
          newBalloon.inflate(radius);
     
     
     
          System.out.println("Current volume of the ballon: "+newBalloon.getVolume());
     
    	 }
    }

    and got
    variable radius might not have been initialized
    newBalloon.inflate(radius);
    ^"

  6. #6
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 697 Times in 679 Posts

    Default Re: Help With BalloonTester

    Java requires that local variables be initialized before use. This can be as simple as:

    double radius = 0.0;

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

    Default Re: Help With BalloonTester

    Quote Originally Posted by GregBrannon View Post
    Java requires that local variables be initialized before use. This can be as simple as:

    double radius = 0.0;
    Thanks. I am still missing a step somewhere. I keep getting 0.0 as the current volume if I use:

     
    public class BalloonTester
    {
       /**
     
       */
       public static void main(String[] args)
     
       {
     
          Balloon newBalloon = new Balloon(0);
          double radius = 0.0;
          double inflate;
          newBalloon.inflate(radius);
     
     
     
          System.out.println("Current volume of the ballon: "+newBalloon.getVolume());
     
    	 }
    }

    I thought that newBalloon.inflate(radius); would inflate it but there is something I am missing.

  8. #8
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 697 Times in 679 Posts

    Default Re: Help With BalloonTester

    Try other numbers, play with it a bit.

  9. #9
    Senior Member
    Join Date
    Jul 2013
    Location
    Europe
    Posts
    666
    Thanks
    0
    Thanked 121 Times in 105 Posts

    Default Re: Help With BalloonTester

    You try to inflate it with 0.0, what do you think is going to happen?

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

    Default Re: Help With BalloonTester

    Quote Originally Posted by Cornix View Post
    You try to inflate it with 0.0, what do you think is going to happen?
    well that is part of the issue. The problem says the balloon starts with a radius of 0. and the class we were provided with says

    //doubles the radius of the balloon
    	public void inflate(double radius)
       {
          savedRadius = savedRadius + radius; //returning total, accumilating 
          }

    I feel like I am supposed to use savedRadius somewhere in the tester but every time I tried I got an error. But even if I am, how are you supposed double a radius of 0? The book says inflate it by the given amount, but we were not given an amount.

  11. #11
    Senior Member
    Join Date
    Jul 2013
    Location
    Europe
    Posts
    666
    Thanks
    0
    Thanked 121 Times in 105 Posts

    Default Re: Help With BalloonTester

    The comment is clearly wrong as you can read from the method:
    public void inflate(double radius)
          {
                savedRadius = savedRadius + radius;
          }
    The balloons radius is saved in the field "savedRadius". The inflate method tages a double value as its argument and increments the saved radius by this value.
    If you call "inflate(3);" then the new radius will be the old radius plus 3. If you call "inflate(0);" then the new radius will be equal to the old radius.