Home Segments Index Top Previous Next

873: Mainline

THE FOOD READER

Food method definition • class 
collectFrom: aFile 
  |inputStream collection food| 
  inputStream := File pathName: aFile. 
  collection := OrderedCollection new. 
  [(food := inputStream nextWord) notNil] 
    whileTrue: [collection add:  
                 ((Food new) name: food; 
                   fCalories: inputStream nextWord asInteger; 
                   cCalories: inputStream nextWord asInteger; 
                   pCalories: inputStream nextWord asInteger)]. 
  inputStream close. 
  ^ collection