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.

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 NSNumbers.

- (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

Parameters

first

Operand to the left of the operation

second

Operand to the right of the operation

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

popOperand

Pops last element from array, like a stack. Removes the element as well.

- (NSNumber *)popOperand

Return Value

NSNumber with the last item in the opreands array.

Declared In

JMMCalculator.m