Results 1 to 2 of 2
  1. #1
    teekei is offline Member
    Join Date
    May 2011
    Posts
    39
    Rep Power
    0

    Default Please Help! I'm Confused.

    I am trying to create a program that takes the user input of color and size to make a bouncing ball in a drawing panel.
    I am supposed to terminate the program after the user gives invalid input two times, I am unsure how to do this.
    How do you terminate program after multiple validation?
    This is the statement in which i have to do it.
    Java Code:
        System.out.print("Enter a color for the ball (yellow or blue): ");
        String colorOfBall = console.next();
        if(colorOfBall.equalsIgnoreCase ("yellow")) {
          System.out.println("The bouncing ball will be yellow.");
        } if (colorOfBall.equalsIgnoreCase ("blue")) {
          System.out.println("The bouncing ball will be blue.");
        } else {
          System.out.println(colorOfBall + " is an invalid choice.");
        }
    Here are some of the requirements for one of the methods in my program in which I am not to sure how to code?

    Each repetition should do the following:

    Move the ball to a new position.
    Update x and y. Specifically, add dx to x and add dy to y.
    Update dx and dy if needed. The ball needs to change direction (bounce) when the ball "hits" the side of the window.
    Pause for 10 ms.

    Java Code:
    import java.awt.*;
    import java.util.*;
    
    public class BouncingBall {
      // simulate a ball bouncing off the walls
      public static void main(String[] args) {
        DrawingPanel panel = new DrawingPanel(500,500);
        Graphics g = panel.getGraphics();
        Scanner console = new Scanner(System.in);
        
        System.out.print("Enter a color for the ball (yellow or blue): ");
        String colorOfBall = console.next();
        if(colorOfBall.equalsIgnoreCase ("yellow")) {
          System.out.println("The bouncing ball will be yellow.");
        } if (colorOfBall.equalsIgnoreCase ("blue")) {
          System.out.println("The bouncing ball will be blue.");
        } else {
          System.out.println(colorOfBall + " is an invalid choice.");
        }
    
    
        
        System.out.print("Enter the size of the ball (3 to 200): ");
        int sizeOfBall = console.nextInt();
        if(sizeOfBall < 3 || sizeOfBall > 200){
          System.out.println(sizeOfBall + "is an invalid value");
        }
        else {
          System.out.println("The size of the bouncing ball will be " + sizeOfBall + ".");
        }
        bounceLoop;
      }
        public static void bounceLoop(DrawingPanel panel, Graphics g, Color c, 
                                  int size, int x, int y, int dx, int dy)
    
      }
      
        
      }

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,800
    Rep Power
    7

    Default Re: Please Help! I'm Confused.

    Quote Originally Posted by teekei View Post
    How do you terminate program after multiple validation?
    One way would be to have a counter. Use a loop and when the counter reaches 2 exit the loop.

Similar Threads

  1. So Confused
    By Need Help in forum New To Java
    Replies: 5
    Last Post: 03-04-2011, 07:18 PM
  2. I am confused
    By prof.deedee in forum New To Java
    Replies: 6
    Last Post: 10-31-2009, 12:32 AM
  3. Very confused Plz help!!
    By ratb0y in forum NetBeans
    Replies: 0
    Last Post: 02-14-2009, 05:34 PM
  4. Confused
    By coldfire in forum New To Java
    Replies: 3
    Last Post: 01-13-2009, 02:00 PM
  5. confused
    By updev in forum AWT / Swing
    Replies: 6
    Last Post: 11-14-2008, 04:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •