View this PageEdit this PageAttachments to this PageHistory of this PageHomeRecent ChangesSearch the SwikiHelp Guide
Hotspots: Admin Pages | Turn-in Site |
Current Links: Cases Final Project Summer 2007

Trayton M1

Object subclass: #Marriage
	instanceVariableNames: 'spouse1 spouse2 weddingDate divorceDate '
	classVariableNames: ''
	poolDictionaries: ''
	category: 'gte991t-M1'!

!Marriage methodsFor: 'displaying' stamp: 'TEO 9/3/2002 22:58'!
asDisplayString
	"comment stating purpose of message"

	^ (spouse1 asDisplayString), ' married ', (spouse2 asDisplayString).! !

!Marriage methodsFor: 'displaying' stamp: 'TEO 9/3/2002 22:58'!
asExplorerString
	"comment stating purpose of message"

	^ self asDisplayString.! !


!Marriage methodsFor: 'accessing' stamp: 'TEO 9/3/2002 22:57'!
divorceDate: newDate
	"sets date of the marriage after the marriage"

	divorceDate := newDate.! !

!Marriage methodsFor: 'accessing' stamp: 'TEO 9/3/2002 22:55'!
spouse1: person1
	"sets one person of the marriage"

	spouse1 := person1.! !

!Marriage methodsFor: 'accessing' stamp: 'TEO 9/3/2002 22:56'!
spouse2: person2
	"sets one person of the marriage"

	spouse2 := person2.! !

!Marriage methodsFor: 'accessing' stamp: 'TEO 9/3/2002 22:57'!
weddingDate: newDate
	"sets date of the marriage"

	weddingDate := newDate.! !


Object subclass: #Person
	instanceVariableNames: 'givenName surName isMale aliases siblings children mother father marriages birthDate birthPlace deathDate properties '
	classVariableNames: ''
	poolDictionaries: ''
	category: 'gte991t-M1'!

!Person methodsFor: 'accessing' stamp: 'TEO 9/3/2002 19:02'!
addAlias: newAlias
	"adds new alias"

	aliases ifNil: [aliases := IdentitySet new].
	aliases add: newAlias.! !

!Person methodsFor: 'accessing' stamp: 'TEO 9/3/2002 23:03'!
addMarriage: newMarriage
	"adds marriage to list of marriages"

	(marriages isNil) ifTrue: [ marriages := IdentitySet new ].
	marriages add: newMarriage.! !

!Person methodsFor: 'accessing' stamp: 'TEO 9/3/2002 19:48'!
born: birthday location: whereInTheWorld
	"born on dating"

	birthDate := birthday.
	birthPlace := whereInTheWorld.! !

!Person methodsFor: 'accessing' stamp: 'TEO 9/3/2002 19:49'!
died: expiresOn
	"death date"

	deathDate := expiresOn.! !

!Person methodsFor: 'accessing' stamp: 'TEO 9/3/2002 17:43'!
givenName: newName
	"set given name"

	givenName := newName.! !

!Person methodsFor: 'accessing' stamp: 'TEO 9/4/2002 18:07'!
hasChild: newChild with: newPartner
	"adds child with sex partner"

	(children isNil) ifTrue: [ children := IdentitySet new ].
	(children includes: newChild) ifFalse: [ "makes sure child already isn't stored"
		children add: newChild.
		(isMale isNil) ifFalse: [
		"if gender is known, then set the father/mother of child, as appropiate"
			(isMale) ifTrue: [ newChild hasFather: self ]
					 ifFalse: [ newChild hasMother: self ]
		].
		"for mirroring, call same message to partner"
		(newPartner isNil) ifFalse: [
			newPartner hasChild: newChild with: self
		]
	].! !

!Person methodsFor: 'accessing' stamp: 'TEO 9/3/2002 19:23'!
hasFather: newFather
	"sets father of person"

	(father isNil) ifTrue: [ father := newFather ].! !

!Person methodsFor: 'accessing' stamp: 'TEO 9/3/2002 19:23'!
hasMother: newMother
	"sets mother if nil"

	(mother isNil) ifTrue: [ mother := newMother ].! !

!Person methodsFor: 'accessing' stamp: 'TEO 9/4/2002 18:08'!
hasSibling: newPerson
	"adds person as a sibling"

	(siblings isNil) ifTrue: [ siblings := IdentitySet new ].
	(siblings includes: newPerson) ifFalse: [
		siblings add: newPerson.
		"for mirroring, adds self to sibling"
		newPerson hasSibling: self
	].! !

!Person methodsFor: 'accessing' stamp: 'TEO 9/4/2002 18:08'!
isFemale
	"makes person female"

	(isMale isNil) ifTrue: [ isMale := false ].
	(children isNil) ifFalse: [
		"sets all children to have this person as mother"
		children do: [ :each | each hasMother: self ]
	].! !

!Person methodsFor: 'accessing' stamp: 'TEO 9/4/2002 18:09'!
isMale
	"makes person male"

	(isMale isNil) ifTrue: [isMale := true ].
	(children isNil) ifFalse: [
		"sets all children to have this person as father"
		children do: [:each | each hasFather: self ]
	].
	! !

!Person methodsFor: 'accessing' stamp: 'TEO 9/3/2002 23:00'!
married: spouse on: weddingDay
	"set wedding info"

	self married: spouse on: weddingDay divorced: nil.! !

!Person methodsFor: 'accessing' stamp: 'TEO 9/3/2002 23:02'!
married: spouse on: weddingDay divorced: divorceDay
	"set wedding info"

	| marriage |
	marriage :=	Marriage new.
	marriage spouse1: self.
	marriage spouse2: spouse.
	marriage weddingDate: weddingDay.
	(divorceDay isNil) ifFalse: [ marriage divorceDate: divorceDay ].
	self addMarriage: marriage.
	spouse addMarriage: marriage.! !

!Person methodsFor: 'accessing' stamp: 'TEO 9/3/2002 23:13'!
record: propName as: propValue
	"adds property"

	| newProp |
	newProp := Property new.
	newProp set: propName to: propValue.
	(properties isNil) ifTrue: [ properties := IdentitySet new ].
	properties add: newProp.! !

!Person methodsFor: 'accessing' stamp: 'TEO 9/3/2002 17:43'!
surName: newName
	"set surname"

	surName := newName.! !


!Person methodsFor: 'displaying' stamp: 'TEO 9/3/2002 20:19'!
asDisplayString
	"toString for display"

	^ (givenName asString), ' ', (surName asString).! !

!Person methodsFor: 'displaying' stamp: 'TEO 9/3/2002 20:19'!
asExplorerString
	"toString for Explorer"

	^ self asDisplayString.! !



!Person methodsFor: 'visualizing' stamp: 'TEO 9/4/2002 21:49'!
printDataAt: location
	"prints basic data with pen at location"

	| lines spacing index base aliasList |
	spacing := 15.
	lines := 5.
	base := lines*spacing+1.
	index := 0.

	self asDisplayString, ((isMale isNil) 	ifTrue: ['']
										ifFalse: [
											(isMale) ifTrue: [' (M)']
													ifFalse: [' (F)']
										])
		displayAt: ( (location x+5)@(location y-(base-(index*spacing))) ).

	index := index+1.
	('Birthday: ', ((birthDate isNil) ifTrue: [''] ifFalse: [birthDate mmddyyyy]) ) 
		displayAt: ( (location x+5)@(location y-(base-(index*spacing))) ).

	index := index+1.
	('Birthplace: ', ((birthPlace isNil) ifTrue:[''] ifFalse: [birthPlace]) )
		displayAt: ( (location x+5)@(location y-(base-(index*spacing))) ).

	index := index+1.
	('Died: ', ((deathDate isNil) ifTrue: [''] ifFalse: [deathDate mmddyyyy]) ) 
		displayAt: ( (location x+5)@(location y-(base-(index*spacing))) ).

	index := index+1.
	aliasList := ''.
	(aliases isNil) ifTrue: [ aliasList := 'none' ]
				ifFalse: [ aliases do: [:alias | aliasList := aliasList, ' ', alias ]
						].
	('Aliases: ', aliasList	)
		displayAt: ( (location x+5)@(location y-(base-(index*spacing))) ).
! !

!Person methodsFor: 'visualizing' stamp: 'TEO 9/4/2002 17:49'!
printSelfAt: center
	"make a box and print data with center as center of box"

	| pen |
	pen := Pen new.
	pen place: center+(-50@-50).
	pen north.
	4 timesRepeat: [ pen go: 100; turn: 90].
	self printDataAt: pen location.! !

!Person methodsFor: 'visualizing' stamp: 'TEO 9/4/2002 22:21'!
visualize
	"visualize this person"

	| location numChildren diffX |
	Display fillWhite.
	location := 300@400.
	self printSelfAt: location.
	(mother isNil) ifFalse: [ mother printSelfAt: location+(-55@-105) ].
	(father isNil) ifFalse: [ father printSelfAt: location+(55@-105) ].
	numChildren := (children ifNil: [0] ifNotNil: [children size]).
	diffX := numChildren - 1 * -50.
	diffX := diffX - (numChildren // 2 * 5).
	children ifNotNil: [
		children do: [:child |
			child printSelfAt: location+(diffX@105).
			diffX := diffX+105
		]
	].
	! !


Object subclass: #Property
	instanceVariableNames: 'name value '
	classVariableNames: ''
	poolDictionaries: ''
	category: 'gte991t-M1'!

!Property methodsFor: 'accessing' stamp: 'TEO 9/3/2002 23:11'!
set: newName to: newValue
	"sets name and value of property"

	name := newName.
	value := newValue.! !


!Property methodsFor: 'displaying' stamp: 'TEO 9/3/2002 23:20'!
asDisplayString
	"display toString"

	^ (name asString), ' = ', (value asString).! !

!Property methodsFor: 'displaying' stamp: 'TEO 9/3/2002 23:15'!
asExplorerString
	"explorer toString"

	^ self asDisplayString.! !


Link to this Page