-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathMath.m
39 lines (32 loc) · 876 Bytes
/
Math.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#import "Math.h"
@implementation Math
@synthesize numbers;
-(id) initWithArray:(NSArray *)givenArray {
if ((self = [super init])) {
self.numbers = [NSMutableArray array];
for (NSString* stringNumber in givenArray) {
[self.numbers addObject: [NSNumber numberWithInt: [stringNumber intValue]]];
}
}
return self;
}
-(int) sum {
int total = 0;
for (NSNumber* number in self.numbers) {
total += [number intValue];
}
return total;
}
-(NSString*) length {
return [NSString stringWithFormat: @"%i", (int)[self.numbers count] ];
}
-(NSString*) max {
int max = [[self.numbers objectAtIndex:0] intValue];
for (NSNumber* number in self.numbers) {
if([number intValue] > max) {
max = [number intValue];
}
}
return [NSString stringWithFormat :@"%d", max];
}
@end