Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
2 changes: 2 additions & 0 deletions TestAssessment/Person.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

@interface Person : NSObject



- (void)setName:(NSString *)name;
- (NSString *)name;

Expand Down
175 changes: 157 additions & 18 deletions TestAssessment/TestViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,46 +18,85 @@ @implementation TestViewController
This method should return any positive NSInteger
(hint: cannot be 0)
*/
- (void)shouldReturnAPositiveNSInteger {
- (NSInteger)shouldReturnAPositiveNSInteger{

// if (i > 0) {
// return i;
// }
// i = i * -1;
// return i;
//}

return 4;
}

/*
This method should return any negative CGFloat
(hint: cannot be 0)
*/
- (void)shouldReturnANegativeCGFloat {
- (CGFloat)shouldReturnANegativeCGFloat{

// if (i < 0) {
// return i;
// }
// i = -i;
//
// return i;

return -8.0;
}

/*
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;
return 'c';
}

/*
This method should return the sum of all numbers from
0 - 99 using a loop (. 1 + 2 + 3 + ... + 98 + 99)
*/
- (NSInteger)shouldReturnSumOf0To100 {
return 0;

int sum = 0;
for (int i = 0; i < 100; i++) {
sum = 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] ...)
*/
- (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;
}

/*
Expand All @@ -67,36 +106,80 @@ Provided a C string (array of chars), return the character
(hint: while loop)
*/
- (char)shouldReturnCharBeforeQ:(char *)str {
return '\0';

// 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') {
//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++;
}

return str [i - 1];

}

/*
This method should return the sum of aNumber + bNumber
*/
- (NSInteger)sumOfAnInteger:(NSInteger)aNumber andAnotherInteger:(NSInteger)bNumber {
return 0;

NSInteger sum = aNumber + bNumber;

return sum;
}


/*
This method should return a YES if aNumber is odd
*/
- (BOOL)isOdd:(NSInteger)aNumber {
return NO;

if (aNumber %2 == 0) {
return NO;
}

return YES;
}

/*
This method should return YES if aNumber is a multiple of 5
*/
- (BOOL)isMultipleOfFive:(NSInteger)aNumber {
return NO;
//the below works!
// if (aNumber %5 == 0) {
// return YES;
// }
// return NO;

//This would also work:
return aNumber %5 == 0;
//same for the above
}

/*
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;
}

Expand All @@ -105,14 +188,15 @@ - (BOOL)returnYesIfThisNumberIsOdd:(NSInteger)aNumber
parameter (hint: command + click on class name to jump to the interface.
*/
- (NSString *)shouldReturnPersonsName:(Person *)person {
return @"";

return [person name];
}

/*
This method should change the person name to "Ada Lovelace"
*/
- (void)changePersonsNameToAdaLovelace:(Person *)person {

- (void) changePersonsNameToAdaLovelace:(Person *)person {
[person setName:@"Ada Lovelace"];
}

/*
Expand All @@ -122,7 +206,11 @@ - (void)changePersonsNameToAdaLovelace:(Person *)person {
3) Set the person's age to 1823
*/
- (Person *)createAndReturnPersonWithSomeProperties {
return [[Person alloc] init];
Person *anotherPerson = [[Person alloc] init];
[anotherPerson setName:@"Santa Clause"];
[anotherPerson setAge:1823];

return anotherPerson;
}

/*
Expand All @@ -133,14 +221,16 @@ - (Person *)createAndReturnPersonWithSomeProperties {

*/
- (void)makePersonSitInChair:(Chair *)chair {

Person *person = [[Person alloc] init];
[person sitInChair:chair];
}

/*
This method provides you an instance of Person as a parameter
Send a message to this Person object telling it to stand up
*/
- (void)makePersonStandUp:(Person *)person {
[person standUp];

}

Expand All @@ -149,7 +239,23 @@ - (void)makePersonStandUp:(Person *)person {
https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSArray_Class/
*/
- (NSArray *)createAndReturnNSArray {
return [[NSArray alloc] init];


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 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
Expand All @@ -161,6 +267,11 @@ - (NSArray *)createAndReturnNSArray {
- (void)changeValueOfIndexFourInArray:(NSMutableArray *)arr
toPersonsName:(Person *)person {

[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
Expand All @@ -172,7 +283,14 @@ - (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
Expand All @@ -184,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