diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..e1b1b4a Binary files /dev/null and b/.DS_Store differ diff --git a/TestAssessment/TestViewController.m b/TestAssessment/TestViewController.m index 1f111c4..26b9b8f 100644 --- a/TestAssessment/TestViewController.m +++ b/TestAssessment/TestViewController.m @@ -19,39 +19,47 @@ @implementation TestViewController This method should return any negative NSInteger (hint: cannot be 0) */ -- (void)shouldReturnANegativeNSInteger { - +- (NSInteger)shouldReturnANegativeNSInteger { + return -23; } /* This method should return any positive CGFloat (hint: cannot be 0) */ -- (void)shouldReturnAPositiveCGFloat { - +- (CGFloat)shouldReturnAPositiveCGFloat { + return 2.3; } /* This method should return a truthy boolean Truthy: Something which evaluates to TRUE. */ -- (void)shouldReturnAPositiveBool { - +- (BOOL)shouldReturnAPositiveBool { + return YES; } /* This method should return any single char from c - l */ -- (void)shouldReturnACharCtoL { +- (char)shouldReturnACharCtoL { + return 'c'; } /* - This method should return the product of all numbers from + This method should return the sum of all numbers from 0 - 1000 using a loop (eg. 1 + 2 + 3 + ... + 998 + 999) */ - (NSInteger)shouldReturnSumOf0To1000 { - return 0; + + NSInteger result = 0; + + for (NSInteger i = 0; i < 1000; i++) { + result += i; + } + + return result; } /* @@ -60,7 +68,14 @@ Given a c array (int[]) and a count, return the average of the numbers within th */ - (NSInteger)shouldReturnAverageOfArrayValues :(int *)arr withSize:(int)count { - return 0; + NSInteger sum = 0; + NSInteger avg; + for (NSInteger i = 0; i < count; i++) { + sum += arr[i]; + } + avg = sum/count; + + return avg; } /* @@ -70,7 +85,13 @@ Provided a C string (array of chars), return the character (hint: assume there will be a char after g) */ - (char)shouldReturnCharAfterG:(char *)str { - return '\0'; + char letterAfterG = '\0'; + for (NSInteger i = 0; i <= strlen(str); i++) { + if (str[i] == 'g') { + letterAfterG = str [i+1]; + } + } + return letterAfterG; } /* @@ -79,7 +100,8 @@ - (char)shouldReturnCharAfterG:(char *)str { */ - (NSInteger)productOfAnInteger:(NSInteger)aNumber andAnotherInteger:(NSInteger)bNumber { - return 0.0; + NSInteger product = aNumber * bNumber; + return product; } @@ -87,14 +109,22 @@ - (NSInteger)productOfAnInteger:(NSInteger)aNumber This method should return a YES if aNumber is Even */ - (BOOL)isEven:(NSInteger)aNumber { + if (aNumber %2 == 0) { + return YES; + } else { return NO; + } } /* This method should return YES if aNumber is a multiple of 10 */ - (BOOL)isMultipleOfTen:(NSInteger)aNumber { + if (aNumber %10 == 0) { + return YES; + } else { return NO; + } } /* @@ -102,7 +132,11 @@ - (BOOL)isMultipleOfTen:(NSInteger)aNumber { */ - (BOOL)returnYesIfThisNumberIsOdd:(NSInteger)aNumber andThisNumberIsEven:(NSInteger)bNumber { + if (aNumber %2 != 0 && bNumber %2 ==0) { + return YES; + } else { return NO; + } } /* @@ -110,13 +144,15 @@ - (BOOL)returnYesIfThisNumberIsOdd:(NSInteger)aNumber (hint: command + click on the class name to see what methods are available) */ - (NSString *)shouldReturnCarModel:(Car *)car { - return @""; + + return [car model]; } /* This method should change the model of the car to "Firebird" */ - (void)changeCarModelToFirebird:(Car *)car { + return [car setModel:@"Firebird"]; } /* @@ -124,7 +160,8 @@ - (void)changeCarModelToFirebird:(Car *)car { the car's current fuel level */ - (CGFloat)tellCarToDrive4MilesAndReturnFuelLevel:(Car *)car { - return 0.0; + [car drive:4]; + return [car fuelLevel]; } /* @@ -135,11 +172,20 @@ - (CGFloat)tellCarToDrive4MilesAndReturnFuelLevel:(Car *)car { 4) Return the car */ - (Car *)createAndReturnANewCar { - return [[Car alloc] init]; + Car *jay = [[Car alloc] init]; + [jay setModel:@"Honda Pilot"]; + [jay drive:6]; + return jay; } - (int)returnSumOfAllItemsGreaterThan100:(int *)arr withSize:(int)size { - return 0; + int result = 0; + for (int i = 0 ; i < size; i++) { + if (arr[i] > 100) { + result += arr[i]; + } + } + return result; } @end