//
//  Student.m
//  StudentManager
//
//  Created by Rich on 2/8/11.
//  Copyright 2011 Swarthmore College. All rights reserved.
//

#import "Student.h"


@implementation Student

@synthesize studentName;
@synthesize gradyear;
@synthesize deptMajor;

- (NSString *)studentName
{
	if (!studentName) studentName = [[NSString alloc] init];
	return studentName;
}

- (id)initWithName:(NSString *)aName
		 deptMajor:(NSString *)aMajor
          gradyear:(int)aYear
{
	if (self = [super init]) {
		self.studentName = aName;
		self.deptMajor = aMajor;
		self.gradyear = aYear;
	}

	return self;
}


- (NSString *)description
{
	return [NSString stringWithFormat:@"%@ (%d): %@", studentName, gradyear, deptMajor];
}

- (void)dealloc
{
	[studentName release];
	[super dealloc];
}


+ (NSMutableArray *)fakeData
{
	NSMutableArray *roster = [[NSMutableArray alloc] initWithObjects:
							  [[Student alloc] initWithName:@"Rich" deptMajor:@"Computer Science" gradyear:1993],
							  [[Student alloc] initWithName:@"Andy" deptMajor:@"Physics" gradyear:1999],
							  [[Student alloc] initWithName:@"Lisa" deptMajor:@"Math" gradyear:1985],
							  [[Student alloc] initWithName:@"James" deptMajor:@"Physics" gradyear:2011],
							  [[Student alloc] initWithName:@"Ashley" deptMajor:@"Computer Science" gradyear:2011],
							  [[Student alloc] initWithName:@"Neil" deptMajor:@"Chemistry" gradyear:2012],
							  [[Student alloc] initWithName:@"Josh" deptMajor:@"Undeclared" gradyear:2013],
							  [[Student alloc] initWithName:@"Sarah" deptMajor:@"Computer Science" gradyear:2012],
							  [[Student alloc] initWithName:@"Doug" deptMajor:@"Computer Science" gradyear:2011],
							  [[Student alloc] initWithName:@"Catie" deptMajor:@"Undeclared" gradyear:2013],
							  nil];
	
	return roster;
}

//Remove from initial handout code
- (void)encodeWithCoder:(NSCoder *)aCoder
{
	//Archive each instance variable using its variable name
	[aCoder encodeObject:studentName forKey:@"studentName"];
	[aCoder encodeObject:deptMajor forKey:@"deptMajor"];
	[aCoder encodeInt:gradyear forKey:@"gradyear"];
}

- (id)initWithCoder:(NSCoder *)aDecoder
{
	[super init];
	
	self.studentName = [aDecoder decodeObjectForKey:@"studentName"];
	self.deptMajor = [aDecoder decodeObjectForKey:@"deptMajor"];
	self.gradyear = [aDecoder decodeIntForKey:@"gradyear"];
	
	return self;
}


@end
