this is the same program as earlier -prof went over it in class, since everyone was having trouble. Now he wants it to work accurately. In other words, in case 2 if an Integer is entered than display the correct message, if is not an integer entered, then display an error message. Same as with case 3 and the double. It does not say anywhere in my book how to do this but he said it would involve the io package. PLEASE HELP! Thanks in advance!
What is this program supposed to do inside the switch statement?
As the program is currently written, the return value from the JOptionPane.showInputDialog is strChoice.
strChoice is parsed as an Integer and used as the argument for the switch.
Inside the switch statement, strChoice is parsed again as an integer, double, etc. And you are supposed to throw an exception if it's not a int/double???
I'm guessing what you are trying to accomplish and I might not be correct, but it seems like there should be two input values. A value that can be a string, int, double, etc. And another that indicates what type that first value is.
Then based on what type was entered you can parse the other value to verify the type is correct.
I am confused too. I have no idea. First he had us do an assignment out of the book and this was the result. Now, he wants a program to check the answer to see if it is an integer or double. If it is not he wants it to display an error message. The whole class is lost on this. I am really new at Java-just a few weeks into this.-I am totally lost!
Okay I looked over my notes again-in case 2 and 3, after the user selects choice 2 or 3, he wants another message requesting an input of that choice. So if you choose 2, it would say,"please enter an integer". Then the data would be checked and if it was an integer you would get a "correct" message. I have been trying this with an if statement but I don't know how to set it to recognize if the entry is an integer or not. Same with the double. This is due in an hour so I am really stressing-sorry.
Sounds like the code above is mostly right. You need to add another input to allow the user to enter the integer/double.
I'm not sure how the prof wants you to verify the entered value is an integer or double. You could use parseInt or parseDouble. Or you could scan the input to make sure it has only numeric characters. In the case of a double it could have numbers or a period.