finally complete

This commit is contained in:
Brent Marohnic 2013-02-12 20:25:31 -05:00
parent 8d1db02fb8
commit 4b76a10638
24 changed files with 384 additions and 324 deletions

View File

@ -7,6 +7,11 @@
objects = {
/* Begin PBXBuildFile section */
658F737B16C9C10400092386 /* insectFactory.m in Sources */ = {isa = PBXBuildFile; fileRef = 658F737A16C9C10400092386 /* insectFactory.m */; };
658F737E16C9C12D00092386 /* baseInsect.m in Sources */ = {isa = PBXBuildFile; fileRef = 658F737D16C9C12D00092386 /* baseInsect.m */; };
658F738116C9C18500092386 /* cricketInsect.m in Sources */ = {isa = PBXBuildFile; fileRef = 658F738016C9C18500092386 /* cricketInsect.m */; };
658F738416C9C19F00092386 /* butterflyInsect.m in Sources */ = {isa = PBXBuildFile; fileRef = 658F738316C9C19F00092386 /* butterflyInsect.m */; };
658F738716C9C1AF00092386 /* antInsect.m in Sources */ = {isa = PBXBuildFile; fileRef = 658F738616C9C1AF00092386 /* antInsect.m */; };
65DF921616C3B0810035C5C9 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 65DF921516C3B0810035C5C9 /* UIKit.framework */; };
65DF921816C3B0810035C5C9 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 65DF921716C3B0810035C5C9 /* Foundation.framework */; };
65DF921A16C3B0810035C5C9 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 65DF921916C3B0810035C5C9 /* CoreGraphics.framework */; };
@ -19,14 +24,19 @@
65DF922F16C3B0810035C5C9 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 65DF922E16C3B0810035C5C9 /* ViewController.m */; };
65DF923216C3B0810035C5C9 /* ViewController_iPhone.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65DF923016C3B0810035C5C9 /* ViewController_iPhone.xib */; };
65DF923516C3B0810035C5C9 /* ViewController_iPad.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65DF923316C3B0810035C5C9 /* ViewController_iPad.xib */; };
65DF923D16C3B2CB0035C5C9 /* Child.m in Sources */ = {isa = PBXBuildFile; fileRef = 65DF923C16C3B2CB0035C5C9 /* Child.m */; };
65DF924016C479840035C5C9 /* ChildFactory.m in Sources */ = {isa = PBXBuildFile; fileRef = 65DF923F16C479840035C5C9 /* ChildFactory.m */; };
65DF924316C49D240035C5C9 /* GoodChild.m in Sources */ = {isa = PBXBuildFile; fileRef = 65DF924216C49D240035C5C9 /* GoodChild.m */; };
65DF924916C4A89C0035C5C9 /* BadChild.m in Sources */ = {isa = PBXBuildFile; fileRef = 65DF924816C4A89C0035C5C9 /* BadChild.m */; };
65DF924C16C4AE670035C5C9 /* RottenChild.m in Sources */ = {isa = PBXBuildFile; fileRef = 65DF924B16C4AE670035C5C9 /* RottenChild.m */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
658F737916C9C10400092386 /* insectFactory.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = insectFactory.h; sourceTree = "<group>"; };
658F737A16C9C10400092386 /* insectFactory.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = insectFactory.m; sourceTree = "<group>"; };
658F737C16C9C12D00092386 /* baseInsect.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = baseInsect.h; sourceTree = "<group>"; };
658F737D16C9C12D00092386 /* baseInsect.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = baseInsect.m; sourceTree = "<group>"; };
658F737F16C9C18500092386 /* cricketInsect.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = cricketInsect.h; sourceTree = "<group>"; };
658F738016C9C18500092386 /* cricketInsect.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = cricketInsect.m; sourceTree = "<group>"; };
658F738216C9C19F00092386 /* butterflyInsect.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = butterflyInsect.h; sourceTree = "<group>"; };
658F738316C9C19F00092386 /* butterflyInsect.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = butterflyInsect.m; sourceTree = "<group>"; };
658F738516C9C1AF00092386 /* antInsect.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = antInsect.h; sourceTree = "<group>"; };
658F738616C9C1AF00092386 /* antInsect.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = antInsect.m; sourceTree = "<group>"; };
65DF921216C3B0810035C5C9 /* APLOC2 Week 1.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "APLOC2 Week 1.app"; sourceTree = BUILT_PRODUCTS_DIR; };
65DF921516C3B0810035C5C9 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
65DF921716C3B0810035C5C9 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
@ -44,16 +54,6 @@
65DF922E16C3B0810035C5C9 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = "<group>"; };
65DF923116C3B0810035C5C9 /* en */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = en; path = en.lproj/ViewController_iPhone.xib; sourceTree = "<group>"; };
65DF923416C3B0810035C5C9 /* en */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = en; path = en.lproj/ViewController_iPad.xib; sourceTree = "<group>"; };
65DF923B16C3B2CB0035C5C9 /* Child.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Child.h; sourceTree = "<group>"; };
65DF923C16C3B2CB0035C5C9 /* Child.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Child.m; sourceTree = "<group>"; };
65DF923E16C479840035C5C9 /* ChildFactory.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ChildFactory.h; sourceTree = "<group>"; };
65DF923F16C479840035C5C9 /* ChildFactory.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ChildFactory.m; sourceTree = "<group>"; };
65DF924116C49D240035C5C9 /* GoodChild.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GoodChild.h; sourceTree = "<group>"; };
65DF924216C49D240035C5C9 /* GoodChild.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GoodChild.m; sourceTree = "<group>"; };
65DF924716C4A89C0035C5C9 /* BadChild.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BadChild.h; sourceTree = "<group>"; };
65DF924816C4A89C0035C5C9 /* BadChild.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BadChild.m; sourceTree = "<group>"; };
65DF924A16C4AE670035C5C9 /* RottenChild.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RottenChild.h; sourceTree = "<group>"; };
65DF924B16C4AE670035C5C9 /* RottenChild.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RottenChild.m; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@ -107,16 +107,16 @@
65DF923016C3B0810035C5C9 /* ViewController_iPhone.xib */,
65DF923316C3B0810035C5C9 /* ViewController_iPad.xib */,
65DF921C16C3B0810035C5C9 /* Supporting Files */,
65DF923B16C3B2CB0035C5C9 /* Child.h */,
65DF923C16C3B2CB0035C5C9 /* Child.m */,
65DF923E16C479840035C5C9 /* ChildFactory.h */,
65DF923F16C479840035C5C9 /* ChildFactory.m */,
65DF924116C49D240035C5C9 /* GoodChild.h */,
65DF924216C49D240035C5C9 /* GoodChild.m */,
65DF924716C4A89C0035C5C9 /* BadChild.h */,
65DF924816C4A89C0035C5C9 /* BadChild.m */,
65DF924A16C4AE670035C5C9 /* RottenChild.h */,
65DF924B16C4AE670035C5C9 /* RottenChild.m */,
658F737916C9C10400092386 /* insectFactory.h */,
658F737A16C9C10400092386 /* insectFactory.m */,
658F737C16C9C12D00092386 /* baseInsect.h */,
658F737D16C9C12D00092386 /* baseInsect.m */,
658F737F16C9C18500092386 /* cricketInsect.h */,
658F738016C9C18500092386 /* cricketInsect.m */,
658F738216C9C19F00092386 /* butterflyInsect.h */,
658F738316C9C19F00092386 /* butterflyInsect.m */,
658F738516C9C1AF00092386 /* antInsect.h */,
658F738616C9C1AF00092386 /* antInsect.m */,
);
path = "APLOC2 Week 1";
sourceTree = "<group>";
@ -205,11 +205,11 @@
65DF922216C3B0810035C5C9 /* main.m in Sources */,
65DF922616C3B0810035C5C9 /* AppDelegate.m in Sources */,
65DF922F16C3B0810035C5C9 /* ViewController.m in Sources */,
65DF923D16C3B2CB0035C5C9 /* Child.m in Sources */,
65DF924016C479840035C5C9 /* ChildFactory.m in Sources */,
65DF924316C49D240035C5C9 /* GoodChild.m in Sources */,
65DF924916C4A89C0035C5C9 /* BadChild.m in Sources */,
65DF924C16C4AE670035C5C9 /* RottenChild.m in Sources */,
658F737B16C9C10400092386 /* insectFactory.m in Sources */,
658F737E16C9C12D00092386 /* baseInsect.m in Sources */,
658F738116C9C18500092386 /* cricketInsect.m in Sources */,
658F738416C9C19F00092386 /* butterflyInsect.m in Sources */,
658F738716C9C1AF00092386 /* antInsect.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -342,6 +342,7 @@
65DF923A16C3B0810035C5C9 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};

View File

@ -1,16 +0,0 @@
//
// BadChild.h
// APLOC2 Week 1
//
// Created by Brent Marohnic on 2/7/13.
// Copyright (c) 2013 Brent Marohnic. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "Child.h"
@interface BadChild : Child
-(void)setAttributes;
@end

View File

@ -1,19 +0,0 @@
//
// BadChild.m
// APLOC2 Week 1
//
// Created by Brent Marohnic on 2/7/13.
// Copyright (c) 2013 Brent Marohnic. All rights reserved.
//
#import "BadChild.h"
#import "Child.h"
@implementation BadChild
-(void)setAttributes
{
intChild = 1;
strName = @"Connor";
}
@end

View File

@ -1,36 +0,0 @@
//
// Child.h
// APLOC2 Week 1
//
// Created by Brent Marohnic on 2/7/13.
// Copyright (c) 2013 Brent Marohnic. All rights reserved.
//
#import <Foundation/Foundation.h>
typedef enum
{
CHILDTYPE_GOOD=0,
CHILDTYPE_BAD,
CHILDTYPE_PERFECT,
CHILDTYPE_ROTTEN
} EChildType;
@interface Child : NSObject
{
@public
NSString *strName;
int intChild;
EChildType childType;
}
-(id)initWithDetails:(int)inpIntChild inpStrName:(NSString*)inpStrName;
-(void)showName;
-(NSString*)showChild;
@property int intChild;
@end

View File

@ -1,48 +0,0 @@
//
// Child.m
// APLOC2 Week 1
//
// Created by Brent Marohnic on 2/7/13.
// Copyright (c) 2013 Brent Marohnic. All rights reserved.
//
#import "Child.h"
@implementation Child
@synthesize intChild;
-(id)initWithDetails:(int)inpIntChild inpStrName:(NSString*)inpStrName
{
self = [super init];
if (self != nil)
{
strName = inpStrName;
intChild = inpIntChild ;
}
return self;
}
-(void)showName
{
NSLog(@"My name is %@", strName);
}
-(NSString*)showChild
{
NSString* returnThis = [[NSString alloc] initWithFormat:@"My name is = %@", strName];
/* NSString* returnThis = [[NSString alloc] initWithFormat:@"blnChild = %c", blnChild];
*/
return returnThis;
}
@end

View File

@ -1,16 +0,0 @@
//
// ChildFactory.h
// APLOC2 Week 1
//
// Created by Brent Marohnic on 2/7/13.
// Copyright (c) 2013 Brent Marohnic. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "Child.h"
@interface ChildFactory : NSObject
-(Child*)GetChild:(int)childType;
@end

View File

@ -1,32 +0,0 @@
//
// ChildFactory.m
// APLOC2 Week 1
//
// Created by Brent Marohnic on 2/7/13.
// Copyright (c) 2013 Brent Marohnic. All rights reserved.
//
#import "ChildFactory.h"
#import "Child.h"
@implementation ChildFactory
-(Child*)GetChild:(int)childType
{
if (childType == 0)
{
return [[Child alloc] initWithDetails:0 inpStrName:@"Jack"];
}
else if (childType == 1)
{
return [[Child alloc] initWithDetails:1 inpStrName:@"Connor"];
}
else if (childType == 3)
{
return [[Child alloc] initWithDetails:3 inpStrName:@"Brent"];
}
return nil;
}
@end

View File

@ -1,16 +0,0 @@
//
// GoodChild.h
// APLOC2 Week 1
//
// Created by Brent Marohnic on 2/7/13.
// Copyright (c) 2013 Brent Marohnic. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "Child.h"
@interface GoodChild : Child
-(void)setAttributes;
@end

View File

@ -1,20 +0,0 @@
//
// GoodChild.m
// APLOC2 Week 1
//
// Created by Brent Marohnic on 2/7/13.
// Copyright (c) 2013 Brent Marohnic. All rights reserved.
//
#import "GoodChild.h"
#import "Child.h"
@implementation GoodChild
-(void)setAttributes
{
intChild = 0;
strName = @"Jack";
childType = CHILDTYPE_GOOD;
}
@end

View File

@ -1,16 +0,0 @@
//
// RottenChild.h
// APLOC2 Week 1
//
// Created by Brent Marohnic on 2/7/13.
// Copyright (c) 2013 Brent Marohnic. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "Child.h"
@interface RottenChild : Child
-(void)setAttributes;
@end

View File

@ -1,19 +0,0 @@
//
// RottenChild.m
// APLOC2 Week 1
//
// Created by Brent Marohnic on 2/7/13.
// Copyright (c) 2013 Brent Marohnic. All rights reserved.
//
#import "RottenChild.h"
#import "Child.h"
@implementation RottenChild
-(void)setAttributes
{
intChild = 3;
strName = @"Brent";
}
@end

View File

@ -7,7 +7,7 @@
//
#import <UIKit/UIKit.h>
@class Child;
#import "insectFactory.h"
@interface ViewController : UIViewController
{

View File

@ -7,11 +7,7 @@
//
#import "ViewController.h"
#import "Child.h"
#import "ChildFactory.h"
#import "GoodChild.h"
#import "BadChild.h"
#import "RottenChild.h"
@interface ViewController ()
@ -21,43 +17,22 @@
- (void)viewDidLoad
{
// create a cricket
cricketInsect *myNewCricket = (cricketInsect*)[insectFactory createNewInsect:CRICKET];
[myNewCricket setSleepDerprivationLevel:5];
ChildFactory *childFactory = [[ChildFactory alloc] init];
if (childFactory != nil)
{
Child *Jack = [childFactory GetChild:0];
[Jack showName];
}
[myNewCricket calculateAnnoyanceFactor];
// create a butterfly
butterflyInsect *myNewButterfly = (butterflyInsect*)[insectFactory createNewInsect:BUTTERFLY];
//Instantiate instances of the subclasses and set their attributes
GoodChild *goodChild = [[GoodChild alloc] init];
{
if (goodChild != nil)
{
[goodChild setAttributes];
}
}
BadChild *badChild = [[BadChild alloc] init];
{
if (badChild != nil)
{
[badChild setAttributes];
}
}
RottenChild *rottenChild = [[RottenChild alloc] init];
{
if (rottenChild != nil)
{
[rottenChild setAttributes];
}
}
[myNewButterfly calculateAnnoyanceFactor];
// create a ant
antInsect *myNewAnt = (antInsect*)[insectFactory createNewInsect:ANT];
[myNewAnt setTypeOfAnt:RED];
[myNewAnt calculateAnnoyanceFactor];
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
@ -67,27 +42,21 @@
firstLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, 50)];
secondLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 51, 320, 50)];
thirdLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 120, 320, 50)];
fourthLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 171, 320, 50)];
thirdLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 170, 320, 50)];
fourthLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 221, 320, 50)];
fifthLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 240, 320, 50)];
sixthLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 291, 320, 50)];
fifthLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 340, 320, 50)];
sixthLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 391, 320, 50)];
Child *firstChild = [[Child alloc] init];
if (firstChild != nil)
{
firstChild.intChild = 2;
secondLabel.text = firstChild.showChild;
}
firstLabel.text = @"Good Child";
secondLabel.text = goodChild->strName;
thirdLabel.text = @"Bad Child";
fourthLabel.text = badChild->strName;
fifthLabel.text = @"Rotten Child";
sixthLabel.text = rottenChild->strName;
firstLabel.text = [NSString stringWithFormat:@"A %@ has been created.", [myNewCricket insectName]];
secondLabel.numberOfLines = 2;
secondLabel.text = [NSString stringWithFormat:@"Its annoyance factor is %d when my sleep deprivation is %d", [myNewCricket annoyanceFactor], [myNewCricket sleepDerprivationLevel]];
thirdLabel.text = [NSString stringWithFormat:@"A %@ has been created.", [myNewButterfly insectName]];
fourthLabel.text = [NSString stringWithFormat:@"Its annoyance factor is %d simply because I like butterflies.", [myNewButterfly annoyanceFactor]];
fourthLabel.numberOfLines = 2;
fifthLabel.text = [NSString stringWithFormat:@"A %@ has been created.", [myNewAnt insectName]];
sixthLabel.text = [NSString stringWithFormat:@"Its annoyance factor is %d", [myNewAnt annoyanceFactor]];
//Show the labels

View File

@ -0,0 +1,28 @@
//
// antInsect.h
// APLOC2 Week 1
//
// Created by Brent Marohnic on 2/11/13.
// Copyright (c) 2013 Brent Marohnic. All rights reserved.
//
#import "baseInsect.h"
@interface antInsect : baseInsect
{
int antType;
}
typedef enum
{
BLACK,
RED,
CARPENTER
} antType;
// insect specific data members used to calculate overall insect annoyance level
@property int homeInvader;
@property int sheerNumber;
@property int typeOfAnt;
@end

View File

@ -0,0 +1,60 @@
//
// antInsect.m
// APLOC2 Week 1
//
// Created by Brent Marohnic on 2/11/13.
// Copyright (c) 2013 Brent Marohnic. All rights reserved.
//
#import "antInsect.h"
@implementation antInsect
@synthesize homeInvader, sheerNumber, typeOfAnt;
// set unique data members from within INIT
-(id)init
{
self = [super init];
if (self != nil)
{
[self setInsectName:@"ant"];
[self setTypeOfAnt:CARPENTER];
[self setHomeInvader: 8];
[self setSheerNumber: 9];
}
return self;
}
// override the base insect method
-(int)calculateAnnoyanceFactor
{
if (typeOfAnt == BLACK)
{
[self setAnnoyanceFactor:self.homeInvader + self.sheerNumber - 2];
[self setInsectName:@"black ant"];
}
else if (typeOfAnt == RED)
{
[self setAnnoyanceFactor:self.homeInvader + self.sheerNumber + 0];
[self setInsectName:@"red ant"];
}
else if (typeOfAnt == CARPENTER)
{
[self setAnnoyanceFactor:self.homeInvader + self.sheerNumber + 2];
[self setInsectName:@"carpenter ant"];
}
else
{
NSLog(@"Please specify a valid type of ant.");
}
NSLog(@"The ant has an annoyance factor of %i out of 20.", self.annoyanceFactor);
return self.annoyanceFactor;
}
@end

View File

@ -0,0 +1,36 @@
//
// baseInsect.h
// APLOC2 Week 1
//
// Created by Brent Marohnic on 2/11/13.
// Copyright (c) 2013 Brent Marohnic. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface baseInsect : NSObject
{
int insectEnum;
}
typedef enum
{
CRICKET,
BUTTERFLY,
ANT
} insectEnum;
// data members for various insect characteristics
@property int numberOfLegs;
@property int numberOfWings;
@property NSString *insectName;
@property int annoyanceFactor;
// initialize
-(id)init;
// calculate annoyance factor
-(int)calculateAnnoyanceFactor;
@end

View File

@ -0,0 +1,37 @@
//
// baseInsect.m
// APLOC2 Week 1
//
// Created by Brent Marohnic on 2/11/13.
// Copyright (c) 2013 Brent Marohnic. All rights reserved.
//
#import "baseInsect.h"
@implementation baseInsect
// allow the compiler to automatically generate get and set methods for the insect properties
@synthesize numberOfLegs, numberOfWings, insectName, annoyanceFactor;
// initialize the base insect
-(id)init
{
self = [super init];
if (self != nil)
{
[self setNumberOfLegs: 0];
[self setNumberOfWings: 0];
[self setInsectName: nil];
[self setAnnoyanceFactor: 0];
}
return self;
}
// calculate annoyance factor
-(int)calculateAnnoyanceFactor
{
NSLog(@"Need to update insectAnnoyanceFactor to include a calculation.");
return 1;
}
@end

View File

@ -0,0 +1,17 @@
//
// butterflyInsect.h
// APLOC2 Week 1
//
// Created by Brent Marohnic on 2/11/13.
// Copyright (c) 2013 Brent Marohnic. All rights reserved.
//
#import "baseInsect.h"
@interface butterflyInsect : baseInsect
// insect specific data members used to calculate overall insect annoyance level
@property int soothingFlightPattern;
@property int pollinator;
@end

View File

@ -0,0 +1,40 @@
//
// butterflyInsect.m
// APLOC2 Week 1
//
// Created by Brent Marohnic on 2/11/13.
// Copyright (c) 2013 Brent Marohnic. All rights reserved.
//
#import "butterflyInsect.h"
@implementation butterflyInsect
@synthesize soothingFlightPattern, pollinator;
// set unique data members from within INIT
-(id)init
{
self = [super init];
if (self != nil)
{
[self setInsectName:@"butterfly"];
[self setSoothingFlightPattern: 0];
[self setPollinator: 0];
}
return self;
}
// override the base insect method
-(int)calculateAnnoyanceFactor
{
[self setAnnoyanceFactor:(soothingFlightPattern + pollinator)];
NSLog(@"The butteryfly has an annoyance factor of %i out of 20.", self.annoyanceFactor);
return self.annoyanceFactor;
}
@end

View File

@ -0,0 +1,19 @@
//
// cricketInsect.h
// APLOC2 Week 1
//
// Created by Brent Marohnic on 2/11/13.
// Copyright (c) 2013 Brent Marohnic. All rights reserved.
//
#import "baseInsect.h"
@interface cricketInsect : baseInsect
// insect specific data members used to calculate overall insect annoyance level
@property int sleepDerprivationLevel;
@property int constantChirping;
@property int nocturnal;
@end

View File

@ -0,0 +1,41 @@
//
// cricketInsect.m
// APLOC2 Week 1
//
// Created by Brent Marohnic on 2/11/13.
// Copyright (c) 2013 Brent Marohnic. All rights reserved.
//
#import "cricketInsect.h"
@implementation cricketInsect
@synthesize sleepDerprivationLevel, constantChirping, nocturnal;
// set unique data members from within INIT
-(id)init
{
self = [super init];
if (self != nil)
{
[self setInsectName:@"cricket"];
[self setSleepDerprivationLevel:0];
[self setConstantChirping: 5];
[self setNocturnal: 5];
}
return self;
}
// override the base insect method
-(int)calculateAnnoyanceFactor
{
[self setAnnoyanceFactor:(sleepDerprivationLevel + constantChirping + nocturnal)];
NSLog(@"The cricket has an annoyance factor of %i out of 20.", self.annoyanceFactor);
return self.annoyanceFactor;
}
@end

View File

@ -0,0 +1,19 @@
//
// insectFactory.h
// APLOC2 Week 1
//
// Created by Brent Marohnic on 2/11/13.
// Copyright (c) 2013 Brent Marohnic. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "baseInsect.h"
#import "cricketInsect.h"
#import "butterflyInsect.h"
#import "antInsect.h"
@interface insectFactory : NSObject
+(baseInsect *)createNewInsect:(int)insectType;
@end

View File

@ -0,0 +1,31 @@
//
// insectFactory.m
// APLOC2 Week 1
//
// Created by Brent Marohnic on 2/11/13.
// Copyright (c) 2013 Brent Marohnic. All rights reserved.
//
#import "insectFactory.h"
@implementation insectFactory
+(baseInsect *)createNewInsect:(int)insectType
{
if (insectType == CRICKET)
{
return [[cricketInsect alloc] init];
}
else if (insectType == BUTTERFLY)
{
return [[butterflyInsect alloc] init];
}
else if (insectType == ANT)
{
return [[antInsect alloc] init];
}
else return nil;
}
@end