From f107559c50b0f36b8bd22603a724517393ce332a Mon Sep 17 00:00:00 2001 From: Derek Date: Sun, 12 Jul 2015 14:56:31 -0400 Subject: [PATCH] complete --- TestAssessment/TestViewController.m | 364 ++++++++++++++++++++++++---- 1 file changed, 319 insertions(+), 45 deletions(-) diff --git a/TestAssessment/TestViewController.m b/TestAssessment/TestViewController.m index 1f111c4..1a243ee 100644 --- a/TestAssessment/TestViewController.m +++ b/TestAssessment/TestViewController.m @@ -1,145 +1,419 @@ // + // TestViewController.m + // TestAssessment + // + // Created by Michael Kavouras on 6/27/15. + // Copyright (c) 2015 Mike Kavouras. All rights reserved. + // + + // Updated by Franklin on 7/11/2015 + + #import "TestViewController.h" + #import "Car.h" + + + @implementation TestViewController + + //Changed positive to negative + /* - This method should return any negative NSInteger - (hint: cannot be 0) + + This method should return any negative NSInteger + + (hint: cannot be 0) + */ -- (void)shouldReturnANegativeNSInteger { + +- (NSInteger)shouldReturnANegativeNSInteger { + + NSInteger myInt = -888; + + return myInt; } + + /* - This method should return any positive CGFloat - (hint: cannot be 0) + + This method should return any positive CGFloat + + (hint: cannot be 0) + */ -- (void)shouldReturnAPositiveCGFloat { + +- (CGFloat)shouldReturnAPositiveCGFloat { + + CGFloat floaty = 4; + + return floaty; } + + /* - This method should return a truthy boolean - Truthy: Something which evaluates to TRUE. + + This method should return a truthy boolean + + Truthy: Something which evaluates to TRUE. + */ -- (void)shouldReturnAPositiveBool { + +- (BOOL)shouldReturnAPositiveBool { + + BOOL yas = YES; + + return yas; } + + /* - This method should return any single char from c - l + + This method should return any single char from c - l + */ -- (void)shouldReturnACharCtoL { + +- (char)shouldReturnACharCtoL { + + return 'd'; } + + /* - This method should return the product of all numbers from - 0 - 1000 using a loop (eg. 1 + 2 + 3 + ... + 998 + 999) + + 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 sum = 0; + + for (NSInteger i = 0; i < 1000; i++) { + + sum += i; + + } + + return sum; + } + + /* - Given a c array (int[]) and a count, return the average of the numbers within the arr - (hint: average = sum / number of elements) + + Given a c array (int[]) and a count, return the average of the numbers within the arr + + (hint: average = sum / number of elements) + */ + - (NSInteger)shouldReturnAverageOfArrayValues :(int *)arr - withSize:(int)count { - return 0; + + withSize:(int)count { + + + + int sum = 0; + + + + for (int i = 0; i < count; i++) { + + sum += arr[i]; + + } + + + + int avg = sum / count; + + + + return avg; + } + + /* - Provided a C string (array of chars), return the character - that immediately succeed the letter g - (ex. "aionkljajvglkjaml" would return the letter 'l') - (hint: assume there will be a char after g) + + Provided a C string (array of chars), return the character + + that immediately succeed the letter g + + (ex. "aionkljajvglkjaml" would return the letter 'l') + + (hint: assume there will be a char after g) + */ + - (char)shouldReturnCharAfterG:(char *)str { - return '\0'; + + + + int i = 0; + + + + while (str[i] != 'g'){ + + i++; + + } + + + + int indexOfCharG = i; + + int indexOfCharAfterG = indexOfCharG + 1; + + + + char charAfterG = str[indexOfCharAfterG]; + + + + return charAfterG; + } + + /* - This method should return the product of aNumber + bNumber - (hint: product = muliplication + + This method should return the product of aNumber + bNumber + + (hint: product = muliplication + */ + - (NSInteger)productOfAnInteger:(NSInteger)aNumber + andAnotherInteger:(NSInteger)bNumber { - return 0.0; + + + + NSInteger product = aNumber * bNumber; + + + + return product; + } + + + /* - This method should return a YES if aNumber is Even + + This method should return a YES if aNumber is Even + */ + - (BOOL)isEven:(NSInteger)aNumber { - return NO; + + + + if (aNumber % 2 == 0) { + + return YES; + + } + + else { + + return NO; + + } + + + } + + /* - This method should return YES if aNumber is a multiple of 10 + + This method should return YES if aNumber is a multiple of 10 + */ + - (BOOL)isMultipleOfTen:(NSInteger)aNumber { + + + + if (aNumber % 10 == 0) { + + return YES; + + } + + + return NO; + } + + /* - This method should return YES is aNumber is odd and bNumber is even + + This method should return YES is aNumber is odd and bNumber is even + */ + - (BOOL)returnYesIfThisNumberIsOdd:(NSInteger)aNumber + andThisNumberIsEven:(NSInteger)bNumber { + + + + if ((aNumber % 2 != 0) && (bNumber % 2 == 0)) { + + return YES; + + } + + + return NO; + } + + /* - This method should return the model of the Car - (hint: command + click on the class name to see what methods are available) + + This method should return the model of the Car + + (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" + + This method should change the model of the car to "Firebird" + */ + - (void)changeCarModelToFirebird:(Car *)car { + + [car setModel:@"Firebird"]; + } + + /* - This method should ask the car to drive 4 miles and then return - the car's current fuel level + + This method should ask the car to drive 4 miles and then return + + the car's current fuel level + */ + - (CGFloat)tellCarToDrive4MilesAndReturnFuelLevel:(Car *)car { - return 0.0; + + [car drive:4]; + + + + return [car fuelLevel]; + } + + /* - This method should: - 1) Create a new instance of Car - 2) Set the model to "Honda Pilot" WATCH YOUR SPELLING - 3) Drive the car 6 miles - 4) Return the car + + This method should: + + 1) Create a new instance of Car + + 2) Set the model to "Honda Pilot" WATCH YOUR SPELLING + + 3) Drive the car 6 miles + + 4) Return the car + */ + - (Car *)createAndReturnANewCar { - return [[Car alloc] init]; + + Car *myRide = [[Car alloc] init]; + + [myRide setModel:@"Honda Pilot"]; + + [myRide drive:6]; + + + + return myRide; + } + + - (int)returnSumOfAllItemsGreaterThan100:(int *)arr withSize:(int)size { - return 0; + + + + int sum = 0; + + + + for (int i = 0; i < size; i++) { + + if (arr[i] > 100) { + + sum += arr[i]; + + } + + } + + + + return sum; + } -@end + + +@end \ No newline at end of file