From 6f0b4fb0ce918acacc4d458d845eb0b73b184f16 Mon Sep 17 00:00:00 2001 From: Artur Lane Date: Tue, 30 Jun 2015 21:59:48 -0400 Subject: [PATCH] I finished --- TestAssessment/Person.h | 4 ++ TestAssessment/TestViewController.m | 97 ++++++++++++++++++++++++----- 2 files changed, 84 insertions(+), 17 deletions(-) diff --git a/TestAssessment/Person.h b/TestAssessment/Person.h index d331757..e210667 100644 --- a/TestAssessment/Person.h +++ b/TestAssessment/Person.h @@ -12,6 +12,10 @@ @interface Person : NSObject +- (void)setName; +- (void)setAge; +- (void)changeName; + - (void)setName:(NSString *)name; - (NSString *)name; diff --git a/TestAssessment/TestViewController.m b/TestAssessment/TestViewController.m index 013428d..58da756 100644 --- a/TestAssessment/TestViewController.m +++ b/TestAssessment/TestViewController.m @@ -11,37 +11,47 @@ #import "Chair.h" -@implementation TestViewController +@implementation TestViewController{ + +} /* This method should return any positive NSInteger (hint: cannot be 0) */ -- (void)shouldReturnAPositiveNSInteger { +- (long)shouldReturnAPositiveNSInteger { + return 20; + } + /* This method should return any negative CGFloat (hint: cannot be 0) */ -- (void)shouldReturnANegativeCGFloat { - +- (float)shouldReturnANegativeCGFloat { + CGFloat negative = -1.5; + return negative; } /* This method should return a falsy boolean Falsey: Something which evaluates to FALSE. */ -- (void)shouldReturnAFalseyBool { - +- (BOOL)shouldReturnAFalseyBool { + + return NO; } /* This method should return a single char from a - z */ -- (void)shouldReturnACharAtoZ { +- (char)shouldReturnACharAtoZ { + char character = 'A'; + return character; + } /* @@ -49,15 +59,31 @@ - (void)shouldReturnACharAtoZ { 0 - 99 using a loop (. 1 + 2 + 3 + ... + 98 + 99) */ - (NSInteger)shouldReturnSumOf0To100 { - return 0; + + NSInteger sum = 0; + + + for (int i = 0; i <= 100; i++) { + + sum += i; + + } + return sum; } /* - Given a c array (int[]) and a count, return the sum of the numbers within the arr - (eg. arr[0] + arr[1] ...) + Given a c array (int[]) and a count, return the sum of the numbers within the arr + (eg. arr[0] + arr[1] ...) */ - (NSInteger)shouldReturnSumOfArrayValues:(int *)arr withSize:(int)count { - return 0; + + NSInteger sum = 0; + + for (int i = 0; i < count; i++) { + sum = sum + arr[i]; + } + + return sum; } /* @@ -67,14 +93,29 @@ Provided a C string (array of chars), return the character (hint: while loop) */ - (char)shouldReturnCharBeforeQ:(char *)str { - return '\0'; + + NSInteger array = strlen(str); + char beforeq; + int i = 0; + while (i < array) { + if (str[i] == 'q') { + beforeq = str[i-1]; + break; + } + i++; + } + + return beforeq; } /* This method should return the sum of aNumber + bNumber */ - (NSInteger)sumOfAnInteger:(NSInteger)aNumber andAnotherInteger:(NSInteger)bNumber { - return 0; + NSInteger sum; + + sum = aNumber + bNumber ; + return sum; } @@ -82,14 +123,23 @@ - (NSInteger)sumOfAnInteger:(NSInteger)aNumber andAnotherInteger:(NSInteger)bNum This method should return a YES if aNumber is odd */ - (BOOL)isOdd:(NSInteger)aNumber { - return NO; + + if (aNumber % 2 == 1) { + return YES; + } else { + return NO; + } } /* This method should return YES if aNumber is a multiple of 5 */ - (BOOL)isMultipleOfFive:(NSInteger)aNumber { + if (aNumber % 5 == 0) { + return YES; + } else { return NO; + } } /* @@ -97,7 +147,11 @@ - (BOOL)isMultipleOfFive:(NSInteger)aNumber { */ - (BOOL)returnYesIfThisNumberIsOdd:(NSInteger)aNumber andThisNumberIsEven:(NSInteger)bNumber { + if (aNumber % 2 == 1 & bNumber % 2 == 0) { + return YES; + } else { return NO; + } } /* @@ -105,14 +159,17 @@ - (BOOL)returnYesIfThisNumberIsOdd:(NSInteger)aNumber parameter (hint: command + click on class name to jump to the interface. */ - (NSString *)shouldReturnPersonsName:(Person *)person { - return @""; + + [person setName:@"Artur"]; + return @"Artur"; } + /* This method should change the person name to "Ada Lovelace" */ - (void)changePersonsNameToAdaLovelace:(Person *)person { - + [person setName:@"Ada Lovelace"]; } /* @@ -122,7 +179,12 @@ - (void)changePersonsNameToAdaLovelace:(Person *)person { 3) Set the person's age to 1823 */ - (Person *)createAndReturnPersonWithSomeProperties { - return [[Person alloc] init]; + Person *mac = [[Person alloc] init]; + [mac setName:@"Santa Clause"]; + [mac setAge:1823]; + + + return mac; } /* @@ -134,6 +196,7 @@ - (Person *)createAndReturnPersonWithSomeProperties { */ - (void)makePersonSitInChair:(Chair *)chair { + } /*