JMMCalculator Class Reference
| Inherits from | NSObject |
| Declared in | JMMCalculator.h JMMCalculator.m |
Overview
This class is created to handle the actual calculation for the calculator.
Most of the work is done in the performOperationWith:and: method. The rest
of the methods just add Operands and Operations. This class can only handle
one JMMCalcOperation at a time.
Warning: Division and Subtraction is not implemented.
Tasks
Public Methods
-
– captureOperand: -
– captureOperation: -
– equate -
– performOperationWith:and: -
– currentResult -
– currentOperation
Private Methods
Extension Methods
-
operandsproperty -
lastOperandproperty -
operationproperty
Properties
lastOperand
Storing the last operand to be used when pressing equals without pressing
and Op UIButton
@property (nonatomic, strong) NSNumber *lastOperandDeclared In
JMMCalculator.moperands
Array of operands. Used like a stack.
@property (nonatomic, strong) NSMutableArray *operandsDeclared In
JMMCalculator.moperation
The current JMMCalcOperation
@property JMMCalcOperation operationDeclared In
JMMCalculator.mInstance Methods
captureOperand:
Add num to the operands stack
- (void)captureOperand:(CGFloat)numParameters
- num
CGFloatto be operated on
Declared In
JMMCalculator.hcaptureOperation:
Set the current operation to op.
- (void)captureOperation:(JMMCalcOperation)opParameters
- op
JMMCalcOperationto be set as the current operation
Declared In
JMMCalculator.hcurrentOperation
Returns the current operation
- (JMMCalcOperation)currentOperationReturn Value
JMMCalcOperation with the current calculator operation
Declared In
JMMCalculator.hcurrentResult
Returns the last result in the operands stack
- (NSNumber *)currentResultReturn Value
NSNumber with the result of the last operand
Declared In
JMMCalculator.hequate
Does a few sanity checks and then calls performOperationWith:and: with the
appropriate two NSNumbers.
- (NSNumber *)equateReturn Value
NSNumber with result from the operation
Declared In
JMMCalculator.hperformOperationWith:and:
Does the Calculation.
- (NSNumber *)performOperationWith:(NSNumber *)first and:(NSNumber *)secondReturn Value
NSNumber result of the calculation
Discussion
If first equaled 2,second equaled 3, and the current operation is AddOp then
this method does 2 + 3.
Warning: Division and Subtraction are not implemented yet.
Declared In
JMMCalculator.h