fork download
  1. "1. Bookクラスの定義"
  2. Object subclass: #Book
  3. instanceVariableNames: 'title author isAvailable'
  4.  
  5. "Bookの初期化"
  6. !Book methodsFor: 'initialization'!
  7. initialize: aTitle author: anAuthor
  8. title := aTitle.
  9. author := anAuthor.
  10. isAvailable := true.! !
  11.  
  12. !Book methodsFor: 'accessing'!
  13. title ^title
  14. isAvailable ^isAvailable
  15. isAvailable: aBoolean isAvailable := aBoolean! !
  16.  
  17. "2. Libraryクラスの定義"
  18. Object subclass: #Library
  19. instanceVariableNames: 'books'
  20.  
  21. !Library methodsFor: 'initialization'!
  22. initialize
  23. books := OrderedCollection new.! !
  24.  
  25. !Library methodsFor: 'actions'!
  26. addBook: aBook
  27. books add: aBook.!
  28.  
  29. checkout: aTitle
  30. | book |
  31. book := books detect: [:b | b title = aTitle] ifNone: [nil].
  32. (book notNil and: [book isAvailable])
  33. ifTrue: [
  34. book isAvailable: false.
  35. Transcript show: aTitle, ' を貸出しました。'; cr]
  36. ifFalse: [
  37. Transcript show: '貸出できません。'; cr]! !
  38.  
  39. "3. 実行例"
  40. | myLibrary book1 |
  41. myLibrary := Library new.
  42. book1 := Book new initialize: 'オブジェクト指向入門' author: '山田太郎'.
  43. myLibrary addBook: book1.
  44.  
  45. "貸出処理の実行"
  46. myLibrary checkout: 'オブジェクト指向入門'."your code goes here"
Success #stdin #stdout #stderr 0.02s 12744KB
stdin
Standard input is empty
stdout
Object: Object error: did not understand #subclass:instanceVariableNames:
MessageNotUnderstood(Exception)>>signal (ExcHandling.st:254)
Object class(Object)>>doesNotUnderstand: #subclass:instanceVariableNames: (SysExcept.st:1448)
UndefinedObject>>executeStatements (prog:3)
Object: nil error: did not understand #methodsFor:
MessageNotUnderstood(Exception)>>signal (ExcHandling.st:254)
UndefinedObject(Object)>>doesNotUnderstand: #methodsFor: (SysExcept.st:1448)
UndefinedObject>>executeStatements (prog:6)
Object: nil error: did not understand #methodsFor:
MessageNotUnderstood(Exception)>>signal (ExcHandling.st:254)
UndefinedObject(Object)>>doesNotUnderstand: #methodsFor: (SysExcept.st:1448)
UndefinedObject>>executeStatements (prog:12)
Object: nil error: did not understand #isAvailable
MessageNotUnderstood(Exception)>>signal (ExcHandling.st:254)
UndefinedObject(Object)>>doesNotUnderstand: #isAvailable (SysExcept.st:1448)
UndefinedObject>>executeStatements (prog:13)
Object: nil error: did not understand #isAvailable
MessageNotUnderstood(Exception)>>signal (ExcHandling.st:254)
UndefinedObject(Object)>>doesNotUnderstand: #isAvailable (SysExcept.st:1448)
UndefinedObject>>executeStatements (prog:15)
Object: Object error: did not understand #subclass:instanceVariableNames:
MessageNotUnderstood(Exception)>>signal (ExcHandling.st:254)
Object class(Object)>>doesNotUnderstand: #subclass:instanceVariableNames: (SysExcept.st:1448)
UndefinedObject>>executeStatements (prog:19)
Object: nil error: did not understand #methodsFor:
MessageNotUnderstood(Exception)>>signal (ExcHandling.st:254)
UndefinedObject(Object)>>doesNotUnderstand: #methodsFor: (SysExcept.st:1448)
UndefinedObject>>executeStatements (prog:21)
Object: nil error: did not understand #books
MessageNotUnderstood(Exception)>>signal (ExcHandling.st:254)
UndefinedObject(Object)>>doesNotUnderstand: #books (SysExcept.st:1448)
UndefinedObject>>executeStatements (prog:22)
Object: nil error: did not understand #methodsFor:
MessageNotUnderstood(Exception)>>signal (ExcHandling.st:254)
UndefinedObject(Object)>>doesNotUnderstand: #methodsFor: (SysExcept.st:1448)
UndefinedObject>>executeStatements (prog:25)
Object: nil error: did not understand #new
MessageNotUnderstood(Exception)>>signal (ExcHandling.st:254)
UndefinedObject(Object)>>doesNotUnderstand: #new (SysExcept.st:1448)
UndefinedObject>>executeStatements (prog:41)
Object: nil error: did not understand #new
MessageNotUnderstood(Exception)>>signal (ExcHandling.st:254)
UndefinedObject(Object)>>doesNotUnderstand: #new (SysExcept.st:1448)
UndefinedObject>>executeStatements (prog:42)
Object: nil error: did not understand #addBook:
MessageNotUnderstood(Exception)>>signal (ExcHandling.st:254)
UndefinedObject(Object)>>doesNotUnderstand: #addBook: (SysExcept.st:1448)
UndefinedObject>>executeStatements (prog:43)
Object: nil error: did not understand #checkout:
MessageNotUnderstood(Exception)>>signal (ExcHandling.st:254)
UndefinedObject(Object)>>doesNotUnderstand: #checkout: (SysExcept.st:1448)
UndefinedObject>>executeStatements (prog:46)
stderr
./prog:7: expected expression
./prog:15: expected expression
./prog:23: expected expression
./prog:26: expected expression
./prog:29: expected expression