From a1b3cd0663470283cdedb5ae2d6c41a8160b5331 Mon Sep 17 00:00:00 2001 From: Justine Gartner Date: Tue, 30 Jun 2015 22:00:52 -0400 Subject: [PATCH 1/2] I have a lot to review --- .DS_Store | Bin 0 -> 6148 bytes TestAssessment/TestViewController.m | 105 +++++++++++++++++++++++++--- 2 files changed, 94 insertions(+), 11 deletions(-) create mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..96bd9f51d09513c4bd4695ab1087cbafa82f00ee GIT binary patch literal 6148 zcmeHKO-jR15dL26qT;5@F5d}+uH42NPf!maB%+8hK~r#tmi4NyfY+C|6J6=s z@6ojNuh-~qHuv&wTM8Qt1Ovgqelx(DEiySW3>ypt1Hr(W0r@^;s$k(b80x2kMq2=) z{6?y9EWL!}WXHmBFytLdvQ(m_CT}s4rPH51u5cU-Egi|5kK|8I-k~IYI@iw{j#L 0) { + return i; + } + i *= -1; + return i; } + /* This method should return any negative CGFloat (hint: cannot be 0) */ -- (void)shouldReturnANegativeCGFloat { +- (CGFloat)shouldReturnANegativeCGFloat: (CGFloat)i{ + + if (i < 0) { + return i; + } + i = -i; + return i; } /* 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 aLetter; +// char anArray[26] = "abcdefghijklmnopqrstuvwxyz"; +// +// while (<#condition#>) { +// <#statements#> +// } + + return aLetter; } /* @@ -49,7 +72,13 @@ - (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 = sum + i; + } + + return sum; } /* @@ -57,7 +86,12 @@ Given a c array (int[]) and a count, return the sum of the numbers within the ar (eg. arr[0] + arr[1] ...) */ - (NSInteger)shouldReturnSumOfArrayValues:(int *)arr withSize:(int)count { - return 0; + + int sum = 0; + for (int i = 0; i < count; i++) { + sum = sum + arr[i]; + } + return sum; } /* @@ -67,6 +101,17 @@ Provided a C string (array of chars), return the character (hint: while loop) */ - (char)shouldReturnCharBeforeQ:(char *)str { + + int i = 0; + + while (str[i] != 'q') { + + if (str[i] == 'q') { + return str[i-1]; + } + + i++; + } return '\0'; } @@ -74,7 +119,10 @@ - (char)shouldReturnCharBeforeQ:(char *)str { This method should return the sum of aNumber + bNumber */ - (NSInteger)sumOfAnInteger:(NSInteger)aNumber andAnotherInteger:(NSInteger)bNumber { - return 0; + + NSInteger sum = aNumber + bNumber; + + return sum; } @@ -82,13 +130,22 @@ - (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 == aNumber %2) { + return NO; + } + + return YES; } /* This method should return YES if aNumber is a multiple of 5 */ - (BOOL)isMultipleOfFive:(NSInteger)aNumber { + + if (aNumber == aNumber %5) { + return YES; + } return NO; } @@ -97,6 +154,11 @@ - (BOOL)isMultipleOfFive:(NSInteger)aNumber { */ - (BOOL)returnYesIfThisNumberIsOdd:(NSInteger)aNumber andThisNumberIsEven:(NSInteger)bNumber { + + if (aNumber != aNumber %2 && bNumber == bNumber %2) { + return YES; + } + return NO; } @@ -105,6 +167,7 @@ - (BOOL)returnYesIfThisNumberIsOdd:(NSInteger)aNumber parameter (hint: command + click on class name to jump to the interface. */ - (NSString *)shouldReturnPersonsName:(Person *)person { + [person name]; return @""; } @@ -112,7 +175,7 @@ - (NSString *)shouldReturnPersonsName:(Person *)person { This method should change the person name to "Ada Lovelace" */ - (void)changePersonsNameToAdaLovelace:(Person *)person { - + [person setName:@"Ada LoveLace"]; } /* @@ -121,7 +184,11 @@ - (void)changePersonsNameToAdaLovelace:(Person *)person { 2) Set the person's name to "Santa Clause" 3) Set the person's age to 1823 */ -- (Person *)createAndReturnPersonWithSomeProperties { +- (Person *)createAndReturnPersonWithSomeProperties: (Person *)person { + + [person setName:@"Santa Clause"]; + [person setAge:1823]; + return [[Person alloc] init]; } @@ -133,7 +200,8 @@ - (Person *)createAndReturnPersonWithSomeProperties { */ - (void)makePersonSitInChair:(Chair *)chair { - + Person *person = [[Person alloc] init]; + [person sitInChair:chair]; } /* @@ -141,6 +209,7 @@ - (void)makePersonSitInChair:(Chair *)chair { Send a message to this Person object telling it to stand up */ - (void)makePersonStandUp:(Person *)person { + [person standUp]; } @@ -149,6 +218,17 @@ - (void)makePersonStandUp:(Person *)person { https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSArray_Class/ */ - (NSArray *)createAndReturnNSArray { + + NSArray *arr; + NSString *object1; + NSString *object2; + NSString *object3; + NSString *object4; + NSString *object5; + NSString *object6; + + arr = [NSArray arrayWithObjects:object1, object2, object3, object4, object5, object6, nil]; + return [[NSArray alloc] init]; } @@ -161,6 +241,8 @@ - (NSArray *)createAndReturnNSArray { - (void)changeValueOfIndexFourInArray:(NSMutableArray *)arr toPersonsName:(Person *)person { + [arr replaceObjectAtIndex:4 withObject:[person name]]; + } // BONUS @@ -172,6 +254,7 @@ - (void)changeValueOfIndexFourInArray:(NSMutableArray *)arr - (NSString *)repeatString:(NSString *)str numberOfTimes:(NSInteger)x { + return @""; } From 1b1e2f9fbde29290f0288107c9b7a2088a114bac Mon Sep 17 00:00:00 2001 From: Justine Gartner Date: Fri, 24 Jul 2015 01:20:02 -0400 Subject: [PATCH 2/2] reviewed and refreshed --- TestAssessment/Person.h | 2 + TestAssessment/TestViewController.m | 162 +++++++++++++++++++--------- 2 files changed, 111 insertions(+), 53 deletions(-) diff --git a/TestAssessment/Person.h b/TestAssessment/Person.h index d331757..42160bf 100644 --- a/TestAssessment/Person.h +++ b/TestAssessment/Person.h @@ -12,6 +12,8 @@ @interface Person : NSObject + + - (void)setName:(NSString *)name; - (NSString *)name; diff --git a/TestAssessment/TestViewController.m b/TestAssessment/TestViewController.m index 605af30..15ec7e6 100644 --- a/TestAssessment/TestViewController.m +++ b/TestAssessment/TestViewController.m @@ -18,28 +18,32 @@ @implementation TestViewController This method should return any positive NSInteger (hint: cannot be 0) */ -- (NSInteger)shouldReturnAPositiveNSInteger:(NSInteger)i { +- (NSInteger)shouldReturnAPositiveNSInteger{ - if (i > 0) { - return i; - } - i *= -1; - return i; -} +// if (i > 0) { +// return i; +// } +// i = i * -1; +// return i; +//} + return 4; +} /* This method should return any negative CGFloat (hint: cannot be 0) */ -- (CGFloat)shouldReturnANegativeCGFloat: (CGFloat)i{ +- (CGFloat)shouldReturnANegativeCGFloat{ - if (i < 0) { - return i; - } - i = -i; +// if (i < 0) { +// return i; +// } +// i = -i; +// +// return i; - return i; + return -8.0; } /* @@ -57,14 +61,15 @@ - (BOOL)shouldReturnAFalseyBool { */ - (char)shouldReturnACharAtoZ{ - char aLetter; -// char anArray[26] = "abcdefghijklmnopqrstuvwxyz"; +// char aLetter; +//// char anArray[26] = "abcdefghijklmnopqrstuvwxyz"; +//// +//// while (<#condition#>) { +//// <#statements#> +//// } // -// while (<#condition#>) { -// <#statements#> -// } - - return aLetter; +// return aLetter; + return 'c'; } /* @@ -73,7 +78,7 @@ - (char)shouldReturnACharAtoZ{ */ - (NSInteger)shouldReturnSumOf0To100 { - NSInteger sum = 0; + int sum = 0; for (int i = 0; i < 100; i++) { sum = sum + i; } @@ -102,17 +107,29 @@ Provided a C string (array of chars), return the character */ - (char)shouldReturnCharBeforeQ:(char *)str { +// int i = 0; +// +// while (str[i] != 'q') { +// +// if (str[i] == 'q') { +// return str[i-1]; +// } +// +// i++; +// } +// //I know this is incorrect +// return str[i]; + + int i = 0; while (str[i] != 'q') { - - if (str[i] == 'q') { - return str[i-1]; + //the loop will continue until it finds a 'q'. when it does it will break out of the loop. No need for an if statement. + i++; } - - i++; - } - return '\0'; + + return str [i - 1]; + } /* @@ -131,7 +148,7 @@ - (NSInteger)sumOfAnInteger:(NSInteger)aNumber andAnotherInteger:(NSInteger)bNum */ - (BOOL)isOdd:(NSInteger)aNumber { - if (aNumber == aNumber %2) { + if (aNumber %2 == 0) { return NO; } @@ -142,11 +159,15 @@ - (BOOL)isOdd:(NSInteger)aNumber { This method should return YES if aNumber is a multiple of 5 */ - (BOOL)isMultipleOfFive:(NSInteger)aNumber { + //the below works! +// if (aNumber %5 == 0) { +// return YES; +// } +// return NO; - if (aNumber == aNumber %5) { - return YES; - } - return NO; + //This would also work: + return aNumber %5 == 0; + //same for the above } /* @@ -155,7 +176,7 @@ - (BOOL)isMultipleOfFive:(NSInteger)aNumber { - (BOOL)returnYesIfThisNumberIsOdd:(NSInteger)aNumber andThisNumberIsEven:(NSInteger)bNumber { - if (aNumber != aNumber %2 && bNumber == bNumber %2) { + if (aNumber %2 != 0 && bNumber %2 == 0) { return YES; } @@ -167,15 +188,15 @@ - (BOOL)returnYesIfThisNumberIsOdd:(NSInteger)aNumber parameter (hint: command + click on class name to jump to the interface. */ - (NSString *)shouldReturnPersonsName:(Person *)person { - [person name]; - return @""; + + return [person name]; } /* This method should change the person name to "Ada Lovelace" */ -- (void)changePersonsNameToAdaLovelace:(Person *)person { - [person setName:@"Ada LoveLace"]; +- (void) changePersonsNameToAdaLovelace:(Person *)person { + [person setName:@"Ada Lovelace"]; } /* @@ -184,12 +205,12 @@ - (void)changePersonsNameToAdaLovelace:(Person *)person { 2) Set the person's name to "Santa Clause" 3) Set the person's age to 1823 */ -- (Person *)createAndReturnPersonWithSomeProperties: (Person *)person { - - [person setName:@"Santa Clause"]; - [person setAge:1823]; +- (Person *)createAndReturnPersonWithSomeProperties { + Person *anotherPerson = [[Person alloc] init]; + [anotherPerson setName:@"Santa Clause"]; + [anotherPerson setAge:1823]; - return [[Person alloc] init]; + return anotherPerson; } /* @@ -219,17 +240,22 @@ - (void)makePersonStandUp:(Person *)person { */ - (NSArray *)createAndReturnNSArray { - NSArray *arr; - NSString *object1; - NSString *object2; - NSString *object3; - NSString *object4; - NSString *object5; - NSString *object6; + + NSArray *arr = [[NSArray alloc] init]; + NSString *object1 = @"one"; + NSString *object2 = @"two"; + NSString *object3 = @"three"; + NSString *object4 = @"four"; + NSString *object5 = @"five"; + NSString *object6 = @"six"; arr = [NSArray arrayWithObjects:object1, object2, object3, object4, object5, object6, nil]; - return [[NSArray alloc] init]; + return arr; + + //also, the following would work: + //return [NSArray arrayWithObjects: @"one", @"two", @"three", @"four", @"five", @"six", nil]; + //Because "arrayWithObjects" does the alloc init for you. } // BONUS @@ -243,6 +269,9 @@ - (void)changeValueOfIndexFourInArray:(NSMutableArray *)arr [arr replaceObjectAtIndex:4 withObject:[person name]]; + //this also would work, but it might not give you "bounce checking", i.e. give you an error msg, it might just silently fail + //arr[4] = [person name]; + } // BONUS @@ -255,7 +284,13 @@ - (void)changeValueOfIndexFourInArray:(NSMutableArray *)arr - (NSString *)repeatString:(NSString *)str numberOfTimes:(NSInteger)x { - return @""; + //from review in class + NSMutableString *finalString = [[NSMutableString alloc] init]; + for (int i = 0; i < x; i++) { + [finalString appendString:str]; + } + + return finalString; } // BONUS @@ -267,7 +302,28 @@ - (NSString *)repeatString:(NSString *)str (ex: [200, 500, 100, 400] returns 800) */ - (int)returnSumWhileSumIsLessThan1050:(int *)arr { - return 0; + + //from in-class review +// int i = 0; +// int sum = 0; +// +// while (sum <= 1050) { +// sum = sum + arr[i]; +// i++; +// } +// +// return sum - arr [i - 1 ]; + + //Caleb's solution + int i = 0; + int sum = 0; + + while (sum + arr[i] <= 1050) { + sum = sum + arr[i]; + i++; + } + + return sum; } @end