The instructer wrote it this way. He wrote everything except the catch
statements so i don't know what to do because i can't change what he
wrote i just need the prompt to go back to the same Enter number 1 or
Enter number 2 if i make an error can some one help Oliver thanks for
your suggestion
> > // Loop until there is no error
> > do
[quoted text clipped - 36 lines]
>
> - Oliver
Oliver Wong - 16 Oct 2006 19:48 GMT
[post-reordered]
>> This problem might be more manageable if you refactored it into
>> several
[quoted text clipped - 17 lines]
> Enter number 2 if i make an error can some one help Oliver thanks for
> your suggestion
Okay, well what you could do, though it might be a bit advanced, is to
write the methods as described above anyway, and when everything is working,
inline the methods: http://www.refactoring.com/catalog/inlineMethod.html
Failing that, I can't think of any strategy other than just reading
through the code, and try to figure out why it isn't doing what you think
it's doing (possibly using a debugger, if you know how). Do you think your
program should work? If so, can you walk through the program, giving the
state of the program (i.e. what values all of the variables are) at each
point, and then run tests to determine if the program state really is what
you expect it to be? If you're not confident your program should work, which
parts are you the least confident about? Look there, and try to explain what
the program is doing to yourself. Then check whether what it's doing will
actually solve the problem you've been asked to solve. If you're not sure
what one specific part is doing, you can ask here.
- Oliver
judith - 16 Oct 2006 21:03 GMT
Now it's adding the numbers back up when i put in a i--; i can't figure
out what to do it's in the catch statement (InputMismatchException
e)catch(InputMismatchException e)
{
keyboard.nextLine();
System.out.println("Error, please enter the number again.");
error = true;
i--;
}
It's supposed to go back to Enter number 1 if there's an error like
entering a letter like i entered t
C:\>java program3JS
How many numbers do you want to enter?
3
Enter number 1
t
Error, please enter the number again.
Enter number 2
3
Enter number 3
3
The average is 2.0
> The instructer wrote it this way. He wrote everything except the catch
> statements so i don't know what to do because i can't change what he
[quoted text clipped - 42 lines]
> >
> > - Oliver