Results 1 to 2 of 2
Thread: Please Help! I'm Confused.
- 10-25-2011, 05:22 AM #1
Member
- Join Date
- May 2011
- Posts
- 39
- Rep Power
- 0
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.
Here are some of the requirements for one of the methods in my program in which I am not to sure how to code?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."); }
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) } }
- 10-25-2011, 05:26 AM #2
Similar Threads
-
So Confused
By Need Help in forum New To JavaReplies: 5Last Post: 03-04-2011, 06:18 PM -
I am confused
By prof.deedee in forum New To JavaReplies: 6Last Post: 10-30-2009, 11:32 PM -
Very confused Plz help!!
By ratb0y in forum NetBeansReplies: 0Last Post: 02-14-2009, 04:34 PM -
Confused
By coldfire in forum New To JavaReplies: 3Last Post: 01-13-2009, 01:00 PM -
confused
By updev in forum AWT / SwingReplies: 6Last Post: 11-14-2008, 03:33 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks