fork download
  1. "========================"
  2. " Book クラス "
  3. "========================"
  4.  
  5. Object subclass: Book [
  6. | title author borrowed |
  7.  
  8. Book class >> title: t author: a [
  9. ^self new initTitle: t author: a
  10. ]
  11.  
  12. initTitle: t author: a [
  13. title := t.
  14. author := a.
  15. borrowed := false.
  16. ^self
  17. ]
  18.  
  19. title [
  20. ^title
  21. ]
  22.  
  23. isBorrowed [
  24. ^borrowed
  25. ]
  26.  
  27. borrow [
  28. borrowed
  29. ifTrue: [ ^false ].
  30. borrowed := true.
  31. ^true
  32. ]
  33.  
  34. returnBook [
  35. borrowed := false.
  36. ]
  37.  
  38. printInfo [
  39. Transcript
  40. show: title;
  41. show: ' / ';
  42. show: author;
  43. show: ' ';
  44. show: (borrowed ifTrue:['(貸出中)'] ifFalse:['(貸出可能)']);
  45. cr.
  46. ]
  47. ]
  48.  
  49. "========================"
  50. " User クラス "
  51. "========================"
  52.  
  53. Object subclass: User [
  54. | name books |
  55.  
  56. User class >> name: n [
  57. ^self new initName: n
  58. ]
  59.  
  60. initName: n [
  61. name := n.
  62. books := OrderedCollection new.
  63. ^self
  64. ]
  65.  
  66. borrow: aBook [
  67. (aBook borrow)
  68. ifTrue: [
  69. books add: aBook.
  70. Transcript show: name; show:' が '; show:aBook title; show:' を借りました'; cr.
  71. ]
  72. ifFalse: [
  73. Transcript show:'貸出できません'; cr.
  74. ].
  75. ]
  76.  
  77. return: aBook [
  78. books remove: aBook ifAbsent: [].
  79. aBook returnBook.
  80. Transcript show:name; show:' が返却しました'; cr.
  81. ]
  82. ]
  83.  
  84. "========================"
  85. " Library クラス "
  86. "========================"
  87.  
  88. Object subclass: Library [
  89. | books |
  90.  
  91. Library class >> newLibrary [
  92. ^self new init
  93. ]
  94.  
  95. init [
  96. books := OrderedCollection new.
  97. ^self
  98. ]
  99.  
  100. addBook: aBook [
  101. books add: aBook.
  102. ]
  103.  
  104. showBooks [
  105. books do: [:b | b printInfo ].
  106. ]
  107. ]
  108.  
  109.  
Success #stdin #stdout 0.01s 7844KB
stdin
Standard input is empty
stdout
Standard output is empty