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

Threaded View

  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


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