Lost all my employee data


#1

Hello everyone at this wonderful forum, this is my first post, and a very important one at that. I run Mac OS X off of a virtual machine on my desktop at my home office, and a recent software update crashed everything.

Luckily I had created a “snapshot” and nothing was too problematic. Sadly, all of the project data that I had typed out of the book have disappeared, except for BeerSong, Class Certificates, Degrees and the Triangle project.

I was wondering if someone would be kind enough to post the employee files for me to copy and paste into Xcode, so that I can continue at chapter 20 without having to go back and find every instance of employee in the book, and have to retype everything.

Thanks so much,
etufte252


#2

Here you are.
Good luck.

Employee.h

[code]#import “Person.h”
@class Asset;

@interface Employee : Person
{
int employeeID;
NSMutableArray *assets;
}

@property int employeeID;

-(void)addAssetsObject:(Asset *)a;
-(unsigned int)valueOfAssets;

@end[/code]

Employee.m

[code]#import “Employee.h”
#import “Asset.h”

@implementation Employee

@synthesize employeeID;

-(void)addAssetsObject:(Asset *)a
{
//is assets nil?
if (!assets) {

    //create an array
    assets = [[NSMutableArray alloc]init];
}
[assets addObject:a];

}

-(unsigned int) valueOfAssets
{
//Sign up the resale value of the assets
unsigned int sum = 0;
for (Asset *a in assets) {
sum += [a resaleValue];
}
return sum;
}

  • (float)bodyMassIndex
    {
    float normalBMI = [super bodyMassIndex];
    return normalBMI * 0.9;
    }

  • (NSString *)description
    {
    return [NSString stringWithFormat:@"<Employee %d: $%d in assets", [self employeeID], [self valueOfAssets]];
    }

-(void) dealloc
{
NSLog(@“deallocating %@”, self);
}

@end
[/code]

Asset.h

[code]#import <Foundation/Foundation.h>

@interface Asset : NSObject
{
NSString *label;
unsigned int resaleValue;
}

@property (strong) NSString *label;
@property unsigned int resaleValue;

@end[/code]

Asset.m

[code]#import “Asset.h”

@implementation Asset

@synthesize label,resaleValue;

-(NSString *)description
{
return [NSString stringWithFormat:@"<%@: $%d >", [self label], [self resaleValue]];
}

-(void)dealloc
{
NSLog(@“deallocating %@”, self);
}

@end[/code]

Person.h

[code]#import <Foundation/Foundation.h>

@interface Person : NSObject
{
float heightInMeters;
int weightInKilos;
}

//methods (replace old methods with property)

@property float heightInMeters;
@property int weightInKilos;

//this method calculate the Body Mass index

-(float)bodyMassIndex;

@end[/code]

Person.m

[code]#import “Person.h”

@implementation Person

//replaced all old method with synthesize

@synthesize heightInMeters, weightInKilos;

-(float)bodyMassIndex
{
float h = [self heightInMeters];
return [self weightInKilos] / (h * h);
//return weightInKilos / (heightInMeters * heightInMeters);
}

@end[/code]

main.m

[code]#import <Foundation/Foundation.h>
#import “Employee.h”
#import “Asset.h”

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

@autoreleasepool {
    
    //Create an array of Employee objects
    NSMutableArray *employees = [[NSMutableArray alloc]init ];
    
    for (int i = 0; i < 10; i++){
        //Create an istance of employee
        Employee *person = [[Employee alloc]init];
        
        //give the instance variable interesting values
         [person setWeightInKilos:90 + i];
         [person setHeightInMeters:1.8 - i/10.0];
         [person setEmployeeID:i];
         
        //put the employee in the employees array
          [employees addObject:person];
        
    }
    
    // Create 10 assets
    
          for (int i = 0 ; i < 10 ; i++) {
              // Create an asset
              Asset *asset = [[Asset alloc]init];
              
              //give it an interesting label
              NSString *currentLabel = [NSString stringWithFormat:@"Laptop %d",i];
              [asset setLabel:currentLabel];
              [asset setResaleValue:i * 17];
              
              //Get a random number between 0 and 9 inclusive
              NSUInteger randomIndex = random() % [employees count];
              
              //Find that employee
              Employee *randomEmployee = [employees objectAtIndex:randomIndex];
              
              //Assgin the asset to the employee
              [randomEmployee addAssetsObject:asset];
              
          }
          NSLog(@"Employees: %@", employees);
          
          NSLog(@"Giving up ownership of one employee");
          
          [employees removeObjectAtIndex:5];
          
          NSLog(@"Giving up ownership of array");
          
          employees = nil;
    
}
return 0;

}
[/code]


#3

Thank you so much, I’ll be sure to be way more careful now.