Hi, Im writing this program, it displays a inputbox asking for a grade(e.g. number), I have it valadated so there can be no letters etc.... I am trying to valadate it so the value entered by the user has to be between 1 & 100, It works and displays a message to the user, but if I enter a number between 1 & 100 I get the same message.....Heres the code, any help much appricated..
Thanks loads in advance..... Thanks joe [ February 01, 2004: Message edited by: Jim Yingst ]
This is so long I haven't been able to see the error yet, but start here: The input checking is the same for the strings received from all three input dialogs, so use the same method for checking. What the check method should do: If it's not an int then Inger.parseInt will throw an exception. Use try/catch to find this error. If you get past try/catch you know you have an int, you just need to make sure it's within the desired range. Maybe you shouldtest for numbers that are too low separately from numbers that are too high, at least until you get things working right. If the program still gives you the same error message when it shouldn't, try printing the number to an output dialog so you can see what it looks like and whether it's getting changed or garbled somewhere along the line.
Elouise's advice above is all excellent. Here's some more. Indent your code carefully. When the indentation jumps around at random it becomes painful to read and therefore harder to understand. E.g.
Your start() method is far too long to understand easily. Try breaking it up into smaller methods. As you did with the last bits, methodone() -two() -three() and methodtotals(). Your start method could be something simple like
Most of the work will be in requestTestScore() of course. Which can also be broken into smaller methods. E.g. you may find it helpful to create a method
or something similar. There are many possible ways to do this. Last, when you write the requestTestScore() method, you may want to consider a do/while loop. It's less common than other loop structures, but it matches what you want to do here - first do something (ask for input), then test a condition to see if you should repeat the first action. You can still do this without do while, but it's something to consider. [ February 01, 2004: Message edited by: Jim Yingst ]
I read ur message they are right, the problem is all the inputs are being taken as the Strings and thats why u are recieving the same error. Try to use Integer.parseInt() to take the values and it will run fine
You can thank my dental hygienist for my untimely aliveness. So tiny:
global solutions you can do at home or in your backyard