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
24 changes: 24 additions & 0 deletions CaesarCipher/CaesarCipher/main.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ @interface CaesarCipher : NSObject

- (NSString *)encode:(NSString *)string offset:(int)offset;
- (NSString *)decode:(NSString *)string offset:(int)offset;
- (BOOL)codeBreaker:(NSString *)string secondCipher:(NSString *)string2;

@end

Expand Down Expand Up @@ -50,11 +51,34 @@ - (NSString *)decode:(NSString *)string offset:(int)offset {
return [self encode:string offset: (26 - offset)];
}

-(BOOL)codeBreaker:(NSString *)string secondCipher:(NSString *)string2{

//Outer loop iterates the first string's offset value
for (int i = 1; i <= 25; i++) {

//Inner loop iterates the second string's offset value
for (int j = 1; j <= 25; j++) {
if ([[self encode:string offset:i] isEqualToString:[self encode:string2 offset:j]]) {
return YES;
break;

}
}
}
return 0;
}
@end


int main(int argc, const char * argv[]) {
@autoreleasepool {
CaesarCipher *check = [[CaesarCipher alloc] init];
NSString *myExampleOne = [check encode:@"carlthegod" offset:2];
NSString *myExampleTwo = [check encode:@"carlthegod" offset:21];
NSLog(@"%@", myExampleOne);
NSLog(@"%@", myExampleTwo);
BOOL checkCodeTwo = [check codeBreaker:myExampleOne secondCipher:myExampleTwo];

NSLog(@"%d", checkCodeTwo);
}
}
55 changes: 55 additions & 0 deletions Election/Election/main.m
Original file line number Diff line number Diff line change
Expand Up @@ -201,11 +201,66 @@ - (BOOL)pollsOpen {

@end

@interface VotingSimulator : NSObject

-(void)simulate;

@end

@implementation VotingSimulator

-(void)simulate{
//Choose name for Election
char electionString[255];
NSLog(@"What would you like to name your election? ");
scanf("%[^\n]", electionString);
NSString *electionName = [NSString stringWithCString:electionString encoding:1];

//Choose name for candidate #1
char candidate1String[255];
NSLog(@"What would you like to name candidate #1? ");
scanf(" %[^\n]", candidate1String);
NSString *candidate1 = [NSString stringWithCString:candidate1String encoding:1];

//Choose name for candidate #2
char candidate2String[255];
NSLog(@"What would you like to name candidate #2? ");
scanf(" %[^\n]", candidate2String);
NSString *candidate2 = [NSString stringWithCString:candidate2String encoding:1];

//Choose name for candidate #3
char candidate3String[255];
NSLog(@"What would you like to name candidate #3? ");
scanf(" %[^\n]", candidate3String);
NSString *candidate3 = [NSString stringWithCString:candidate3String encoding:1];

Election *POTUS = [[Election alloc] initWithElectionName:electionName];

Contender *Candidate1 = [[Contender alloc] initWithName:candidate1];
Contender *Candidate2 = [[Contender alloc] initWithName:candidate2];
Contender *Candidate3 = [[Contender alloc] initWithName:candidate3];

[POTUS addContender:Candidate1];
[POTUS addContender:Candidate2];
[POTUS addContender:Candidate3];


ElectionManager *Manager = [[ElectionManager alloc] init];

[Manager manage:POTUS];
[Manager initiatePolling];
[Manager displayResults];

}

@end


int main(int argc, const char * argv[]) {
@autoreleasepool {

VotingSimulator *testRun = [[VotingSimulator alloc] init];
[testRun simulate];
}
return 0;
}
113 changes: 86 additions & 27 deletions Person/Person/main.m
Original file line number Diff line number Diff line change
@@ -1,63 +1,122 @@
//
// main.m
// Person
// inClassPersonAssignment
//
// Created by Michael Kavouras on 6/21/15.
// Copyright (c) 2015 Mike Kavouras. All rights reserved.
// Created by Jovanny Espinal on 6/23/15.
// Copyright (c) 2015 Jovanny Espinal. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface Person: NSObject
@interface Person : NSObject

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

- (void)setCity:(NSString *)city;
- (NSString *)city;
-(void)setPhoneNUmber:(NSString *)phoneNumber;
-(NSString *)phoneNumber;

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

-(void)changePersonsName:(Person *)aPerson
toName:(NSString *)newName;

-(BOOL)checkSameCity:(Person *)aPerson;

-(Person *)haveChild;

- (void)setPhoneNumber:(NSString *)phoneNumber;
- (NSString *)phoneNumber;

@end

@implementation Person {
NSString *_name;
NSString *_phoneNumber;
NSString *_city;
NSString *_phoneNumber;
NSString *_name;
}

- (void)setName:(NSString *)name {
_name = name;
-(void)setCity:(NSString *)city{
_city = city;
}
-(NSString *)city{
return _city;
}

- (NSString *)name {
return _name;
-(void)setPhoneNUmber:(NSString *)phoneNumber{
_phoneNumber = phoneNumber;
}
-(NSString *)phoneNumber{
return _phoneNumber;
}

- (void)setCity:(NSString *)city {
_city = city;
-(void)setName:(NSString *)name{
_name = name;
}
-(NSString *)name{
return _name;
}

- (NSString *)city {
return _city;
-(void)changePersonsName:(Person *)aPerson
toName:(NSString *)newName{
[aPerson setName:newName];
}

- (void)setPhoneNumber:(NSString *)phoneNumber {
_phoneNumber = phoneNumber;
-(BOOL)checkSameCity:(Person *)aPerson{
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is 100% correct. Suggestion to make it more concise: Just return the result of the isEqualToString method call...

- (BOOL)checkSameCity:(Person *)aPerson {
   return [[aPerson city] isEqualToString: [self city]];
}

if ([[aPerson city] isEqualToString: [self city]]) {
return YES;
}
else {
return NO;
}
}

- (NSString *)phoneNumber {
return _phoneNumber;
-(Person *)haveChild{
Person *Abc = [[Person alloc] init];
[Abc setPhoneNUmber:[self phoneNumber]];
[Abc setCity:[self city]];

return Abc;
}

@end


int main(int argc, const char * argv[]) {
@autoreleasepool {
// insert code here...
NSLog(@"Hello, World!");
Person *carl = [[Person alloc] init];
[carl setName:@"Carl"];
[carl setCity:@"Okinawa"];
[carl setPhoneNUmber:@"8604788872"];

NSString *carlsName = [carl name];

NSLog(@"The object's name is: %@.", carlsName);

[carl setName:@"Steven"];
carlsName = [carl name];

NSLog(@"The object's new name is: %@.", carlsName);
NSLog(@"The object's city is: %@.", [carl city]);

[carl setCity:@"Brooklyn"];
NSLog(@"The object's new city is: %@.", [carl city]);

Person *mike = [[Person alloc] init];
[mike setCity:@"New York City"];
[mike changePersonsName:carl toName:@"Carl"];
BOOL citiesAreTheSame = [mike checkSameCity:carl];

NSLog(@"The carl object is now: %@", [carl name]);


NSLog(@"%d", citiesAreTheSame);

Person *mikesChild = [mike haveChild];

NSLog(@"Mike's baby's city is: %@.", [mikesChild city]);

[mike changePersonsName:mikesChild toName:@"Abc"];

NSLog(@"The mikesChild object's name is now: %@", [mikesChild name]);
}
return 0;
}
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,5 @@ Write a program to simulate an election. Create a class called **VotingSimulator
4. Ask the ElectionManager to ***initiatePolling***
5. Follow the instructions on the console. After each round of polling you will be asked(within the console) whether you want to continue or not.
6. Ask the ElectionManager to ***displayResults***

Literally anything.