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

Thread: Need help with while loop

  1. #1
    Junior Member
    Join Date
    Sep 2013
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Need help with while loop

    Ok so I attatched the assignment the question I'm on is #2 and this is what I have down so far. It asks for a return type but I'm not sure what to return? Any advice would be greatly appreciated I've been working on this assignment for what seems like forever.
    public class cannonball
    {
        private double velocity;
        private double time;
        final double GRAVFORCE = 9.81;
        private double height;
        private double heightFormula;
        private double maxHeight;
     
        public cannonball(double Velocity)
        {
            velocity = Velocity;
            height = 0;
            heightFormula = 0;
        }
        public double simulateFlight()
        {
          time = 0;
            while(height>0||time<100)
            {
                heightFormula = (velocity*time)-0.5*GRAVFORCE*Math.pow(time,2);
                height = velocity*time;
                time++;
                velocity = velocity - GRAVFORCE*time;
                str = time + "\t\t"+ velocity +"\t\t" + height + "\t\t"+ heightFormula;
            }
     
        }
    }
    Attached Files Attached Files


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Need help with while loop

    It asks for a return type
    What is the "It" you are asking about? If you are getting an error from the compiler, please copy the full text of the error message and paste it here.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Sep 2013
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Need help with while loop

    it is an error which reads "missing return statement"

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Need help with while loop

    "missing return statement"
    That says that the compiler can not find a return statement in a method that is defined to return a value.
    Add a return statement at the end of the method where the error is that returns a value of the type shown in the methods definition.

    BTW that is not a full error message. Here is a sample compiler error message:
    The message should show the source with a ^ under the location of the error.
    Here is a sample from the javac compiler:
    TestSorts.java:138: cannot find symbol
    symbol  : variable var
    location: class TestSorts
             var = 2;
             ^
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Sep 2013
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Need help with while loop

    pic1.jpg
    this is a picture of the entire message

  6. #6
    Junior Member
    Join Date
    Sep 2013
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Need help with while loop

    I want to return three things from the one method is that possible?

  7. #7
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Need help with while loop

    If you put them in a collection of some kind, yes. But you can't do:

    return this, that, andTheOtherThing;

Similar Threads

  1. help with when the for loop is met and i want to run the while loop again
    By m49er704 in forum What's Wrong With My Code?
    Replies: 9
    Last Post: March 22nd, 2013, 09:03 AM
  2. For loop, the first command in the loop does not get executed the 2nd time..
    By lina_inverse in forum Loops & Control Statements
    Replies: 1
    Last Post: October 16th, 2012, 09:00 PM
  3. [SOLVED] Please help with my while loop that turned into infinite loop!
    By Hazmat210 in forum What's Wrong With My Code?
    Replies: 9
    Last Post: March 10th, 2012, 11:22 PM
  4. Converting a while loop to a for loop and a for loop to a while loop.
    By awesom in forum Loops & Control Statements
    Replies: 3
    Last Post: February 26th, 2012, 08:57 PM
  5. [SOLVED] My while loop has run into an infinite loop...?
    By kari4848 in forum Loops & Control Statements
    Replies: 3
    Last Post: March 1st, 2011, 12:05 PM