I'm trying to write a program, so when a user enters their name a specific message is displayed. However, it's been a while since I used Java and eclipse, so I'm not sure what I'm doing wrong, or what I need to do.
There is something very wrong about your booleans; that on line 9 can only be true false if somebody clicked the cancel button on your option pane, and that on line 11 can never be false. Why re you using option pane? That is very old‑fashioned style.
You need to tell us what is going wrong and what you expected to happen. What does the show message dialogue method return? Can you assign that to a String?
[Edit]Sorry, got a true when I should have said false.
Campbell, thanks for replying. I am getting the error message "Type mismatch: cannot convert from void to String" for lines 12 and 14. As for line 9, eclipse prompted me to change to a Boolean from what I originally had, which was String n1=s1. I didn't know that option pane was old-fashioned.
As for what I expect to happen, I just want to set up a way that I can have a user enter their name, and based on their name, have a particular message appear that I made to correspond to their name.
Thanks K. Tsang. Now it runs, but when I type in her name, it comes up please try again. It seems to not be running through the if, but goes right to the else.
OK, so I was told that message boxes are out. So I used a different input, but it's not running right? No matter who's name I put in, it skips to the part about Star Wars and doesn't run anything else. Can someone see what I'm doing wrong?
The code you posted doesn't compile. "default" needs a ":" after it and there are two missing close braces. After fixing that, it seems to work, but...
There are several ways this code can be improved. One is using correct indentation. Another is getting the code out of the main() method (see MainIsAPain).
Post by:autobot
This. Exactly this. This is what my therapist has been talking about. And now with a tiny ad:
a bit of art, as a gift, the permaculture playing cards