fork download
  1. "============================================================"
  2. " 大学図書館貸出システム"
  3. " Ideone / GNU Smalltalk向け"
  4. "============================================================"
  5.  
  6.  
  7. "------------------------------------------------------------"
  8. " Book:図書"
  9. "------------------------------------------------------------"
  10.  
  11. Object subclass: #Book
  12. instanceVariableNames: 'isbn title author available'
  13. classVariableNames: ''
  14. poolDictionaries: ''
  15. category: 'UniversityLibrary'!
  16.  
  17.  
  18. !Book class methodsFor: 'instance creation'!
  19.  
  20. isbn: anISBN title: aTitle author: anAuthor
  21. ^self new
  22. initializeISBN: anISBN
  23. title: aTitle
  24. author: anAuthor
  25. !
  26.  
  27. !
  28.  
  29.  
  30. !Book methodsFor: 'initialization'!
  31.  
  32. initializeISBN: anISBN title: aTitle author: anAuthor
  33. isbn := anISBN.
  34. title := aTitle.
  35. author := anAuthor.
  36. available := true.
  37. ^self
  38. !
  39.  
  40. !
  41.  
  42.  
  43. !Book methodsFor: 'accessing'!
  44.  
  45. isbn
  46. ^isbn
  47. !
  48.  
  49. title
  50. ^title
  51. !
  52.  
  53. author
  54. ^author
  55. !
  56.  
  57. isAvailable
  58. ^available
  59. !
  60.  
  61. !
  62.  
  63.  
  64. !Book methodsFor: 'loan operations'!
  65.  
  66. borrow
  67. available
  68. ifFalse: [self error: 'この図書はすでに貸出中です'].
  69.  
  70. available := false
  71. !
  72.  
  73. returnBook
  74. available
  75. ifTrue: [self error: 'この図書は貸出されていません'].
  76.  
  77. available := true
  78. !
  79.  
  80. !
  81.  
  82.  
  83. !Book methodsFor: 'printing'!
  84.  
  85. printOn: aStream
  86. aStream
  87. nextPutAll: title;
  88. nextPutAll: ' / ';
  89. nextPutAll: author;
  90. nextPutAll: ' [ISBN: ';
  91. nextPutAll: isbn;
  92. nextPutAll: ']'.
  93.  
  94. available
  95. ifTrue: [aStream nextPutAll: ' 貸出可能']
  96. ifFalse: [aStream nextPutAll: ' 貸出中']
  97. !
  98.  
  99. !
  100.  
  101.  
  102. "------------------------------------------------------------"
  103. " Member:図書館利用者"
  104. "------------------------------------------------------------"
  105.  
  106. Object subclass: #Member
  107. instanceVariableNames: 'memberId name memberType'
  108. classVariableNames: ''
  109. poolDictionaries: ''
  110. category: 'UniversityLibrary'!
  111.  
  112.  
  113. !Member class methodsFor: 'instance creation'!
  114.  
  115. id: anId name: aName type: aType
  116. ^self new
  117. initializeId: anId
  118. name: aName
  119. type: aType
  120. !
  121.  
  122. !
  123.  
  124.  
  125. !Member methodsFor: 'initialization'!
  126.  
  127. initializeId: anId name: aName type: aType
  128. memberId := anId.
  129. name := aName.
  130. memberType := aType.
  131. ^self
  132. !
  133.  
  134. !
  135.  
  136.  
  137. !Member methodsFor: 'accessing'!
  138.  
  139. memberId
  140. ^memberId
  141. !
  142.  
  143. name
  144. ^name
  145. !
  146.  
  147. memberType
  148. ^memberType
  149. !
  150.  
  151. loanLimit
  152. memberType = #student
  153. ifTrue: [^3].
  154.  
  155. memberType = #teacher
  156. ifTrue: [^10].
  157.  
  158. ^2
  159. !
  160.  
  161. loanPeriod
  162. memberType = #teacher
  163. ifTrue: [^30].
  164.  
  165. ^14
  166. !
  167.  
  168. typeName
  169. memberType = #student
  170. ifTrue: [^'学生'].
  171.  
  172. memberType = #teacher
  173. ifTrue: [^'教職員'].
  174.  
  175. ^'その他'
  176. !
  177.  
  178. !
  179.  
  180.  
  181. !Member methodsFor: 'printing'!
  182.  
  183. printOn: aStream
  184. aStream
  185. nextPutAll: name;
  186. nextPutAll: ' [利用者番号: ';
  187. nextPutAll: memberId;
  188. nextPutAll: ', 区分: ';
  189. nextPutAll: self typeName;
  190. nextPutAll: ']'
  191. !
  192.  
  193. !
  194.  
  195.  
  196. "------------------------------------------------------------"
  197. " Loan:貸出記録"
  198. " 日付は、例を簡単にするため整数の日数で表現する"
  199. "------------------------------------------------------------"
  200.  
  201. Object subclass: #Loan
  202. instanceVariableNames: 'book member loanDay dueDay returnedDay'
  203. classVariableNames: ''
  204. poolDictionaries: ''
  205. category: 'UniversityLibrary'!
  206.  
  207.  
  208. !Loan class methodsFor: 'instance creation'!
  209.  
  210. book: aBook member: aMember loanDay: aLoanDay
  211. ^self new
  212. initializeBook: aBook
  213. member: aMember
  214. loanDay: aLoanDay
  215. !
  216.  
  217. !
  218.  
  219.  
  220. !Loan methodsFor: 'initialization'!
  221.  
  222. initializeBook: aBook member: aMember loanDay: aLoanDay
  223. book := aBook.
  224. member := aMember.
  225. loanDay := aLoanDay.
  226. dueDay := aLoanDay + member loanPeriod.
  227. returnedDay := nil.
  228. ^self
  229. !
  230.  
  231. !
  232.  
  233.  
  234. !Loan methodsFor: 'accessing'!
  235.  
  236. book
  237.  
Success #stdin #stdout #stderr 0.01s 8152KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
./prog:237: parse error, expected '!'