Hi folks,
I have written an application that acts like a simple calculator and performs addition or subtraction of numbers entered in a certain
pattern. I was successful in writing the program and compiling it and exceuting it. I am having little bit of trouble in handling exceptions.
I have to handle four kinds of errors and i did get two of them. But didnt know how to achieve the other two.
1. No input at all. The user presses �calculate� and the input text field has nothing to calculate. Put the message, �Enter An Expression� in the top text field if this occurs (and make the bottom text field blank.
2. Wrong number of operators and operands. There should always be an odd number of items (�55� is one instance, � 3 + 2� is three, etc.) Report �Wrong Number Of Elements� in the bottom text field if there is not an odd number of elements (after you tokenize on �+� and �-� ).
3. Invalid operand. If you find something that is not a valid operand (i.e., not an integer) in a place where you would expect an operand to be, then leave the user�s expression in the top text field and put the message �Invalid Operand Or Operator� in the bottom text field.
D. Invalid operator. If you find something that is not a valid operator (i.e., not a �+� or a �-�) in a place where you would expect to find an operator, then leave the user�s expression in the top text field and put the message �Invalid Operand Or Operator� in the bottom text field.
Below is my code:
Thank you,
kt
[ July 29, 2005: Message edited by: kanaka tam ]
[ July 29, 2005: Message edited by: kanaka tam ]