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.

Need Help Altering My Application, Please...

Hi everyone,

I've been coding for a few weeks now through a class and I'm still struggling a bit with it. I'm prepping for an exam and my teacher gave us a practice test (but wont give answers) to prep. I've been stuck on one of the questions for days and the class tutors haven't been a help.

The instructions are:

Alter the code to allow the user to input ANY numbers for a box to flip. For example, if the user inputs 2,5,100, your program should print: This range is out of bounds. Please choose a range that is within (0,0) and (width ,height ), where width and height are the actual width and height of the picture chosen. If the user enters constraints that will not cause an out of bounds error, then flip that portion of the picture and continue. If the user enters constraints that will cause an out of bounds error, then reprompt them. This should not count towards the 3 flips for each vertical and horizontal. There should still be a total of 6 FLIPS; 3 horizontal, 3 vertical.

The instructions were confusing for me at first, so to put it simply, alter the code so rather than get an out of bounds error, the user is reprompted.

Re: Need Help Altering My Application, Please...

First, do you have to use BufferedReader for your text input? The Scanner class seems to be a little bit easier for this.

Now, he wants you to include a way to check the input for the legal bounds, right? So how do you check? You can use an if/then statement after you input the values, right? Or you can use a while loop that runs until the values are correct.

For example:

Scanner a =new Scanner(System.in);//inputSystem.out.print("Input a number less than 10: ");//promptwhile(Integer.parseInt(a.next())>=10)//gets and checks the input in a loop{System.out.print("Input a number less than 10: ");//re-prompts if need be.}

This is a good example of something that prompts the user for an input, and will keep re-prompting until a certain condition is met, in this case until a number less than ten is inputted. The check for you may be more complex, and may need some equations to run, but it is fairly easily done.