Forums Register Login

What am I doing wrong?

+Pie Number of slices to send: Send
Hello,

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.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
Thank you very much!
You can't have everything. Where would you put it?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 958 times.
Similar Threads
How close am I in getting this program right?
Simple Problem (if else statments)
Making a simple blackjack game
math program help..
Do while error, I'm going crazy
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 02:06:46.