"============================================================"
" 大学図書館貸出システム"
" Ideone / GNU Smalltalk向け"
"============================================================"
"------------------------------------------------------------"
" Book:図書"
"------------------------------------------------------------"
Object subclass: #Book
instanceVariableNames: 'isbn title author available'
classVariableNames: ''
poolDictionaries: ''
category: 'UniversityLibrary'!
!Book class methodsFor: 'instance creation'!
isbn: anISBN title: aTitle author: anAuthor
^self new
initializeISBN: anISBN
title: aTitle
author: anAuthor
!
!
!Book methodsFor: 'initialization'!
initializeISBN: anISBN title: aTitle author: anAuthor
isbn := anISBN.
title := aTitle.
author := anAuthor.
available := true.
^self
!
!
!Book methodsFor: 'accessing'!
isbn
^isbn
!
title
^title
!
author
^author
!
isAvailable
^available
!
!
!Book methodsFor: 'loan operations'!
borrow
available
ifFalse: [self error: 'この図書はすでに貸出中です'].
available := false
!
returnBook
available
ifTrue: [self error: 'この図書は貸出されていません'].
available := true
!
!
!Book methodsFor: 'printing'!
printOn: aStream
aStream
nextPutAll: title;
nextPutAll: ' / ';
nextPutAll: author;
nextPutAll: ' [ISBN: ';
nextPutAll: isbn;
nextPutAll: ']'.
available
ifTrue: [aStream nextPutAll: ' 貸出可能']
ifFalse: [aStream nextPutAll: ' 貸出中']
!
!
"------------------------------------------------------------"
" Member:図書館利用者"
"------------------------------------------------------------"
Object subclass: #Member
instanceVariableNames: 'memberId name memberType'
classVariableNames: ''
poolDictionaries: ''
category: 'UniversityLibrary'!
!Member class methodsFor: 'instance creation'!
id: anId name: aName type: aType
^self new
initializeId: anId
name: aName
type: aType
!
!
!Member methodsFor: 'initialization'!
initializeId: anId name: aName type: aType
memberId := anId.
name := aName.
memberType := aType.
^self
!
!
!Member methodsFor: 'accessing'!
memberId
^memberId
!
name
^name
!
memberType
^memberType
!
loanLimit
memberType = #student
ifTrue: [^3].
memberType = #teacher
ifTrue: [^10].
^2
!
loanPeriod
memberType = #teacher
ifTrue: [^30].
^14
!
typeName
memberType = #student
ifTrue: [^'学生'].
memberType = #teacher
ifTrue: [^'教職員'].
^'その他'
!
!
!Member methodsFor: 'printing'!
printOn: aStream
aStream
nextPutAll: name;
nextPutAll: ' [利用者番号: ';
nextPutAll: memberId;
nextPutAll: ', 区分: ';
nextPutAll: self typeName;
nextPutAll: ']'
!
!
"------------------------------------------------------------"
" Loan:貸出記録"
" 日付は、例を簡単にするため整数の日数で表現する"
"------------------------------------------------------------"
Object subclass: #Loan
instanceVariableNames: 'book member loanDay dueDay returnedDay'
classVariableNames: ''
poolDictionaries: ''
category: 'UniversityLibrary'!
!Loan class methodsFor: 'instance creation'!
book: aBook member: aMember loanDay: aLoanDay
^self new
initializeBook: aBook
member: aMember
loanDay: aLoanDay
!
!
!Loan methodsFor: 'initialization'!
initializeBook: aBook member: aMember loanDay: aLoanDay
book := aBook.
member := aMember.
loanDay := aLoanDay.
dueDay := aLoanDay + member loanPeriod.
returnedDay := nil.
^self
!
!
!Loan methodsFor: 'accessing'!
book