Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

finished RandomPossession project

  • Loading branch information...
commit 06851c5a4ea5a3a3d8dcd937dd3f59489ff68192 1 parent 25f7595
@paulyoder authored
View
6 RandomPossessions/RandomPossessions.xcodeproj/project.pbxproj
@@ -10,6 +10,7 @@
DAAAFBF91539B32A008AD089 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DAAAFBF81539B32A008AD089 /* Foundation.framework */; };
DAAAFBFC1539B32A008AD089 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = DAAAFBFB1539B32A008AD089 /* main.m */; };
DAAAFC001539B32A008AD089 /* RandomPossessions.1 in CopyFiles */ = {isa = PBXBuildFile; fileRef = DAAAFBFF1539B32A008AD089 /* RandomPossessions.1 */; };
+ DAAAFC081539BCF7008AD089 /* BNRItem.m in Sources */ = {isa = PBXBuildFile; fileRef = DAAAFC071539BCF7008AD089 /* BNRItem.m */; };
/* End PBXBuildFile section */
/* Begin PBXCopyFilesBuildPhase section */
@@ -31,6 +32,8 @@
DAAAFBFB1539B32A008AD089 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
DAAAFBFE1539B32A008AD089 /* RandomPossessions-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "RandomPossessions-Prefix.pch"; sourceTree = "<group>"; };
DAAAFBFF1539B32A008AD089 /* RandomPossessions.1 */ = {isa = PBXFileReference; lastKnownFileType = text.man; path = RandomPossessions.1; sourceTree = "<group>"; };
+ DAAAFC061539BCF7008AD089 /* BNRItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BNRItem.h; sourceTree = "<group>"; };
+ DAAAFC071539BCF7008AD089 /* BNRItem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BNRItem.m; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -74,6 +77,8 @@
isa = PBXGroup;
children = (
DAAAFBFB1539B32A008AD089 /* main.m */,
+ DAAAFC061539BCF7008AD089 /* BNRItem.h */,
+ DAAAFC071539BCF7008AD089 /* BNRItem.m */,
DAAAFBFF1539B32A008AD089 /* RandomPossessions.1 */,
DAAAFBFD1539B32A008AD089 /* Supporting Files */,
);
@@ -139,6 +144,7 @@
buildActionMask = 2147483647;
files = (
DAAAFBFC1539B32A008AD089 /* main.m in Sources */,
+ DAAAFC081539BCF7008AD089 /* BNRItem.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
View
BIN  ....xcodeproj/project.xcworkspace/xcuserdata/paul.xcuserdatad/UserInterfaceState.xcuserstate
Binary file not shown
View
36 RandomPossessions/RandomPossessions/BNRItem.h
@@ -0,0 +1,36 @@
+//
+// BNRItem.h
+// RandomPossessions
+//
+// Created by Paul Yoder on 4/14/12.
+// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+@interface BNRItem : NSObject
+{
+ NSString *itemName;
+ NSString *serialNumber;
+ int valueInDollars;
+ NSDate *dateCreated;
+}
+
++ (id)randomItem;
+
+- (id)initWithItemName:(NSString *)name
+ valueInDollars:(int)value
+ serialNumber:(NSString *)sNumber;
+
+- (void)setItemName:(NSString *)str;
+- (NSString *)itemName;
+
+- (void)setSerialNumber:(NSString *)str;
+- (NSString *)serialNumber;
+
+- (void)setValueInDollars:(int)i;
+- (int)valueInDollars;
+
+- (NSDate *)dateCreated;
+
+@end
View
117 RandomPossessions/RandomPossessions/BNRItem.m
@@ -0,0 +1,117 @@
+//
+// BNRItem.m
+// RandomPossessions
+//
+// Created by Paul Yoder on 4/14/12.
+// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
+//
+
+#import "BNRItem.h"
+
+@implementation BNRItem
+
+- (id)initWithItemName:(NSString *)name
+ valueInDollars:(int)value
+ serialNumber:(NSString *)sNumber
+{
+ // Call the superclass's designated initializer
+ self = [super init];
+
+ if (self) {
+ [self setItemName:name];
+ [self setValueInDollars:value];
+ [self setSerialNumber:sNumber ];
+ dateCreated = [[NSDate alloc] init];
+ }
+
+ return self;
+}
+
++ (id)randomItem
+{
+ // Create an array of three adjectives
+ NSArray *randomAdjectiveList = [NSArray arrayWithObjects:@"Fluffy", @"Rusty", @"Shiny", nil];
+
+ // Create an array of three nouns
+ NSArray *randomNounList = [NSArray arrayWithObjects:@"Bear", @"Spork", @"Mac", nil];
+
+ // Get the index of a random adjective/noun from the lists
+ // Note: The % operator, called the modulo operator, gives
+ // you the remainder. So adjectiveIndex is a random number
+ // from 0 to 2 inclusive.
+ NSInteger adjectiveIndex = rand() % [randomAdjectiveList count];
+ NSInteger nounIndex = rand() % [randomNounList count];
+
+ // Note that NSInteger is not an object, but a type definition
+ // for "unsigned long"
+ NSString *randomName = [NSString stringWithFormat:@"%@ %@",
+ [randomAdjectiveList objectAtIndex:adjectiveIndex],
+ [randomNounList objectAtIndex:nounIndex]];
+
+ int randomValue = rand() % 100;
+
+ NSString *randomSerialNumber = [NSString stringWithFormat:@"%c%c%c%c%c",
+ '0' + rand() % 10,
+ 'A' + rand() % 26,
+ '0' + rand() % 10,
+ 'A' + rand() % 26,
+ '0' + rand() % 10];
+
+ BNRItem *newItem = [[self alloc] initWithItemName:randomName
+ valueInDollars:randomValue
+ serialNumber:randomSerialNumber];
+
+ return newItem;
+}
+
+- (id)init
+{
+ return [self initWithItemName:@"Item" valueInDollars:0 serialNumber:@""];
+}
+
+
+- (void)setItemName:(NSString *)str
+{
+ itemName = str;
+}
+- (NSString *)itemName
+{
+ return itemName;
+}
+
+- (void)setSerialNumber:(NSString *)str
+{
+ serialNumber = str;
+}
+- (NSString *)serialNumber
+{
+ return serialNumber;
+}
+
+- (void)setValueInDollars:(int)i
+{
+ valueInDollars = i;
+}
+- (int)valueInDollars
+{
+ return valueInDollars;
+}
+
+- (NSDate *)dateCreated
+{
+ return dateCreated;
+}
+
+- (NSString *)description
+{
+ NSString *descriptionString =
+ [[NSString alloc] initWithFormat:@"%@ (%@): Worth $%d, recorded on %@",
+ itemName,
+ serialNumber,
+ valueInDollars,
+ dateCreated];
+
+ return descriptionString;
+}
+
+@end
View
20 RandomPossessions/RandomPossessions/main.m
@@ -7,16 +7,28 @@
//
#import <Foundation/Foundation.h>
+#import "BNRItem.h"
int main(int argc, const char * argv[])
{
- @autoreleasepool {
+ @autoreleasepool {
- // insert code here...
- NSLog(@"Hello, World!");
+ // Create a mutable array object, store its adrees in items variable
+ NSMutableArray *items = [[NSMutableArray alloc] init];
+ for (int i = 0; i < 10; i++) {
+ BNRItem *p = [BNRItem randomItem];
+ [items addObject:p];
}
- return 0;
+
+ for (BNRItem *item in items) {
+ NSLog(@"%@", item);
+ }
+
+ // Destroy the array pointed to by items
+ items = nil;
+ }
+ return 0;
}
Please sign in to comment.
Something went wrong with that request. Please try again.