Skip to content

Instantly share code, notes, and snippets.

Created October 12, 2008 01:43
Show Gist options
  • Save anonymous/16350 to your computer and use it in GitHub Desktop.
Save anonymous/16350 to your computer and use it in GitHub Desktop.
import <Foundation/CPObject.j>
@implementation CalculatorLogic : CPObject
{
CPNumber currentValue;
CPString acumulatedValue;
var decimalPointActive;
//1 * 0.1 * 0.1 in Js = 0.010000000000000002 :) Strings never fails!!!
id changeValueNotifyDelegate;
}
- (id)init
{
self = [super init];
if (self)
{
currentValue = [[CPString alloc] init];
acumulatedValue = [[CPNumber alloc] initWithInt:0];
decimalPointActive = NO;
}
return self;
}
-(void)setNotifyInstance:(id)aInstance
{
changeValueNotifyDelegate = aInstance;
}
-(void)notifyInstance
{
if ([changeValueNotifyDelegate respondsToSelector:@selector(displayValueChanged:)])
{
[changeValueNotifyDelegate displayValueChanged:[self getCurrentValue]];
}
}
-(CPString)getCurrentValue
{
return currentValue;
}
-(void)press: (CPString)aNumber
{
if (([currentValue length] != 0) || ([aNumber isEqualToString:"0"] == NO))
{
currentValue = currentValue + aNumber;
[self notifyInstance];
}
}
-(void)buttonOne
{
[self press:"1"];
}
-(void)buttonTwo
{
[self press:"2"];
}
-(void)buttonThree
{
[self press:"3"];
}
-(void)buttonFour
{
[self press:"4"];
}
-(void)buttonFive
{
[self press:"5"];
}
-(void)buttonSix
{
[self press:"6"];
}
-(void)buttonSeven
{
[self press:"7"];
}
-(void)buttonEight
{
[self press:"8"];
}
-(void)buttonNine
{
[self press:"9"];
}
-(void)buttonZero
{
[self press:"0"];
}
-(void)buttonDot
{
if (decimalPointActive == NO)
{
[self press:"."];
}
decimalPointActive = YES;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment