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
-
operands
property -
lastOperand
property -
operation
property
Properties
lastOperand
Storing the last operand to be used when pressing equals without pressing
and Op UIButton
@property (nonatomic, strong) NSNumber *lastOperand
Declared In
JMMCalculator.m
operands
Array of operands. Used like a stack.
@property (nonatomic, strong) NSMutableArray *operands
Declared In
JMMCalculator.m
operation
The current JMMCalcOperation
@property JMMCalcOperation operation
Declared In
JMMCalculator.m
Instance Methods
captureOperand:
Add num to the operands stack
- (void)captureOperand:(CGFloat)num
Parameters
- num
CGFloat
to be operated on
Declared In
JMMCalculator.h
captureOperation:
Set the current operation to op.
- (void)captureOperation:(JMMCalcOperation)op
Parameters
- op
JMMCalcOperation
to be set as the current operation
Declared In
JMMCalculator.h
currentOperation
Returns the current operation
- (JMMCalcOperation)currentOperation
Return Value
JMMCalcOperation
with the current calculator operation
Declared In
JMMCalculator.h
currentResult
Returns the last result in the operands stack
- (NSNumber *)currentResult
Return Value
NSNumber with the result of the last operand
Declared In
JMMCalculator.h
equate
Does a few sanity checks and then calls performOperationWith:and: with the
appropriate two NSNumber
s.
- (NSNumber *)equate
Return Value
NSNumber
with result from the operation
Declared In
JMMCalculator.h
performOperationWith:and:
Does the Calculation.
- (NSNumber *)performOperationWith:(NSNumber *)first and:(NSNumber *)second
Return 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