Simple Calculator… Yeah Right

First, HUGE thanks to Karel. Without his help, I would not have been able to finish this assignment on time.

So, as I stated in my previous entry, this week’s Java homework was to make a calculator that took user input like “3 + 4” or “3.7 / 6” kind of thing. I was having all sorts of trouble with it.

First try:
Tried to implement the program with a method that checked the sign and then passed the value and a true/false value that checked if the numbers were actually numbers.

Second try:
Could not get the program to recognize the signs I was putting in. Solution: figure out the ASCII value and use a SWITCH statement to handle the 5 different operations. Next, implement a TRY-CATCH statement to test if the numbers were numbers and life would be good? No. Asked for help from the professor about my program and he responded “No TRY-CATCH. Can’t use those, they haven’t been covered yet”.

Third try:
With some input from Karel, I used hasNextDouble() which returns boolean values. If TRUE, then go through the program, if FALSE, program quits before an error can occur. By then using the equals(char) method, I was able to get the whole program to work. Took a last hit of the crowbar to get it to compile correctly, but it works. Even had enough time to do a INT or DOUBLE checker to return even cleaner values.

Link to code



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: