Skip to content

Instantly share code, notes, and snippets.

@projectxcappe
Created September 6, 2011 16:57
Show Gist options
  • Save projectxcappe/1198168 to your computer and use it in GitHub Desktop.
Save projectxcappe/1198168 to your computer and use it in GitHub Desktop.
Angry Stockholders iOS
//
// Angry_StockholdersViewController.h
// Angry Stockholders
//
// Created by Cassidy Pangell on 7/21/11.
//
#import <UIKit/UIKit.h>
@interface Angry_StockholdersViewController : UIViewController {
IBOutlet UILabel *time;
NSTimer *myTicker;
UIButton *fourty;
UIButton *sixty;
UIButton *eighty;
UIButton *ghundred;
UIButton *hundred;
UIButton *delFourty;
UIButton *delSixty;
UIButton *delEighty;
UIButton *delGHundred;
UIButton *delHundred;
IBOutlet UILabel *t_fourty;
IBOutlet UILabel *t_sixty;
IBOutlet UILabel *t_eighty;
IBOutlet UILabel *t_ghundred;
IBOutlet UILabel *t_hundred;
IBOutlet UIButton *resetBtn;
IBOutlet UIButton *startBtn;
IBOutlet UIButton *stopBtn;
IBOutlet UILabel *total;
IBOutlet UIView *modelView;
}
-(IBAction)start;
-(IBAction)stop;
-(IBAction)reset;
-(IBAction)mFourty;
-(IBAction)mSixty;
-(IBAction)mEighty;
-(IBAction)mGHundred;
-(IBAction)mHundred;
-(IBAction)dFourty;
-(IBAction)dSixty;
-(IBAction)dEighty;
-(IBAction)dGHundred;
-(IBAction)dHundred;
-(IBAction)helpButton;
@end
//
// Angry_StockholdersViewController.m
// Angry Stockholders
//
// Created by Cassidy Pangell on 7/21/11.
//
#import "Angry_StockholdersViewController.h"
#include "HelpViewController.h"
@implementation Angry_StockholdersViewController
-(IBAction)helpButton {
HelpViewController *screen = [[HelpViewController alloc] initWithNibName:nil bundle:nil];
screen.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:screen animated:YES];
[screen release];
}
-(NSString*)PlusOne:(NSString*)strText{
return [NSString stringWithFormat:@"%d", ([strText intValue] + 1)];
}
-(NSString*)MinusOne:(NSString*)strText{
if ([strText intValue] > 0) {
return [NSString stringWithFormat:@"%d", ([strText intValue] - 1)];
} else {
return [NSString stringWithFormat:@"%d", ([strText intValue])];
}
}
-(IBAction)start{
myTicker = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(showActivity) userInfo:nil repeats:YES];
resetBtn.enabled = NO;
startBtn.enabled = NO;
stopBtn.enabled = YES;
}
-(IBAction)stop{
[myTicker invalidate];
resetBtn.enabled = YES;
startBtn.enabled = YES;
stopBtn.enabled = NO;
}
-(IBAction)reset{
time.text = @"0";
total.text = @"0.00";
t_fourty.text = @"0";
t_sixty.text = @"0";
t_eighty.text = @"0";
t_hundred.text = @"0";
t_ghundred.text = @"0";
stopBtn.enabled = NO;
}
//Method takes all current values and updates the salary in seconds to the counting timer in seconds.
//Every time the counter increases, the salary updates.
-(void)showActivity{
int currentTime = [time.text intValue];
int newTime = currentTime + 1;
time.text = [NSString stringWithFormat:@"%d", newTime];
int seconds = 31536000; //1 year of seconds
double fourtyVal = [t_fourty.text doubleValue] * 40000;
double sixtyVal = [t_sixty.text doubleValue] * 55000;
double eightyVal = [t_eighty.text doubleValue] * 75000;
double hundredVal = [t_hundred.text doubleValue] * 95000;
double ghundredVal = [t_ghundred.text doubleValue] * 105000;
double newSalary = [total.text doubleValue] + ((fourtyVal + sixtyVal + eightyVal + hundredVal + ghundredVal) / seconds);
total.text = [NSString stringWithFormat:@"%.2f", newSalary];
}
-(IBAction)mFourty{
t_fourty.text = [self PlusOne:t_fourty.text];
}
-(IBAction)mSixty{
t_sixty.text = [self PlusOne:t_sixty.text];
}
-(IBAction)mEighty{
t_eighty.text = [self PlusOne:t_eighty.text];
}
-(IBAction)mGHundred{
t_ghundred.text = [self PlusOne:t_ghundred.text];
}
-(IBAction)mHundred{
t_hundred.text = [self PlusOne:t_hundred.text];
}
-(IBAction)dFourty{
t_fourty.text = [self MinusOne:t_hundred.text];
}
-(IBAction)dSixty{
t_sixty.text = [self MinusOne:t_sixty.text];
}
-(IBAction)dEighty{
t_eighty.text = [self MinusOne:t_eighty.text];
}
-(IBAction)dGHundred{
t_ghundred.text = [self MinusOne:t_ghundred.text];
}
-(IBAction)dHundred{
t_hundred.text = [self MinusOne:t_hundred.text];
}
- (void)dealloc
{
[super dealloc];
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
[super viewDidLoad];
}
*/
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
@end
@mattshapiro
Copy link

I don't know from Objective C but I would think if you put similar UI elements into some arrays or collections it could help cut some repetition.

Also, did you consider the concept of a "work year"? Your calculation currently includes the time employees spend "off the clock" (even asleep) in its second count. You should get a much more dramatic number if you, say, figure on a 40 hour work week and use that for your "annual seconds" count (ie 40 * 60 * 60 * 52 ... and that doesn't even include vacation time!) :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment