File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes What am I doing wrong? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "What am I doing wrong?" Watch "What am I doing wrong?" New topic

What am I doing wrong?

Rich Nelson

Joined: Sep 22, 2007
Posts: 15

For my homework, I was asked to write a simple math test program with two levels of difficulty: easy and hard.

The problem is, when I run the program and choose a difficulty level, it acts as if I spelled the difficulty wrong. It would probably be best if someone could run this program to see what exactly happens. I've been trying to figure out what I'm doing wrong for hours now; everything seems to basic and easy, I can't imagine what I'm doing wrong.
Tony Docherty

Joined: Aug 07, 2007
Posts: 2839
The problem is your test for the level entered by the user. == does not test that the words are the same, it tests that the object references are the same ie they reference the same object. When testing that 2 objects are equal in value to each other you should always use the equals() method. Although in this case it might be better to use the equalsIgnoreCase() method which is a special equals test provided by the String class to allow an equals test to be done regardless of the capitalisation of the strings.
Rich Nelson

Joined: Sep 22, 2007
Posts: 15
Thank you very much!
I agree. Here's the link:
subject: What am I doing wrong?
jQuery in Action, 3rd edition