You are not logged in.

Dear visitor, welcome to Jabaco - Community. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

NoLars

Beginner

  • "NoLars" is male
  • "NoLars" started this thread

Posts: 2

Date of registration: Feb 4th 2010

Location: Germany

Occupation: Developer, IT-Trainer

  • Send private message

1

Saturday, February 6th 2010, 12:34pm

Sample Application "Calculator" - unary operations

Problem
When executing unary operations (operations that take just one parameter) in a situation where no second parameter exists you receive a runtime error java.lang.NumberFormatException: empty String.

Details
To reproduce the problem, start calculator sample application, then enter a number such as "64". Now try to calculate the press spare root [sqrt]. You will now see runtime error java.lang.NumberFormatException: empty String.

No try this: Restart the calculator application. Enter this sequence: [5] [*] [5] [=]

The correct result 25.0 is dieplayed. Now pess [sqrt]. Instead of 5, the square root of 25, you will see 2.23606797749979.

The operation is applied on the value 5.

In Sub ExecuteCalc the unary operations sqrt, ^2 and ^3 use myMemSecondValue.

Suggestion

1) Change Sub ExcueteCalc as follows

Case "sqrt": SetValue(sqr(myMemValue))
Case "^2": SetValue(myMemValue ^ 2)
Case "^3": SetValue(myMemValue ^ 3)

2) Include logic for operator precedence and decision depending on number of

operators existing in memory. Treat [=] as an operator returning the last result to myMemValue and display in case only one or no values exist in memory.

(to be continued ...)

Rate this thread
WoltLab Burning Board