Thursday, May 17th 2012, 6:39pm UTC+2

You are not logged in.

  • Login
  • Register

NoLars

Beginner

Posts: 2

Location: Germany

Occupation: Developer, IT-Trainer

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