From VisualWorks® NonCommercial, 7.4.1 of May 30, 2006 on October 31, 2006 at 10:26:45 am RefactoringExercise Smalltalk false private Smalltalk.* Refactor Exercise Refactor Exercise Course RefactoringExercise Core.Object false none id students Refactor Exercise Refactor Exercise RefactoringExercise.Course Some COmment StudentTest RefactoringExercise XProgramming.SUnit.TestCase false none student course Refactor Exercise Refactor Exercise Student RefactoringExercise Core.Object false none courses name Refactor Exercise Refactor Exercise RefactoringExercise.Course class instance creation new "Answer a newly created and initialized instance." ^super new initialize RefactoringExercise.Course initialize-release initialize "Initialize a newly created instance. This method must answer the receiver." id := nil. students := OrderedCollection new. ^self RefactoringExercise.Course calculation classAverage |sum average count grades| sum := 0.0. average := 0.0. count := 0. students do: [ :student| grades := student gradesFor: id. grades do:[: grade | sum:=sum+grade.]. count:=count+grades size.]. average := sum / count. Transcript show: 'Class average for ' ; show: id ; show: ' with ' ; show: students size ; show: ' students is: ' ; show: average; cr. studentAverageFor: aStudentName |student sum grades average | student := nil. students do: [ :each | each name = aStudentName ifTrue: [student := each.].]. grades := student gradesFor: id. sum := 0.0. grades do: [ :each | sum := sum + each. ]. average := sum / grades size. Transcript show: 'Course: ' ; show: id ; show: ' Student: ' ; show: aStudentName ; cr. Transcript show: ' Class Average= ' ; show: average; cr. RefactoringExercise.Course accessing addStudent: aStudent students add: aStudent id ^id id: anObject id := anObject students ^students RefactoringExercise.Student class instance creation new "Answer a newly created and initialized instance." ^super new initialize RefactoringExercise.Student initialize-release initialize "Initialize a newly created instance. This method must answer the receiver." courses := Dictionary new. ^self RefactoringExercise.Student accessing gradesFor: aCourseId ^courses at: aCourseId name ^name. name: aString name:= aString. addGrade: aCourseId value:anInteger |grades| grades := courses at: aCourseId. grades add: anInteger. addCourse: aCourse courses at: aCourse id put: OrderedCollection new. RefactoringExercise.StudentTest class instance creation new "Answer a newly created and initialized instance." ^super new initialize RefactoringExercise.StudentTest initialize-release setUp student := Student new. course := Course new. student name: 'Bob'. course id: 'CS2335'. course addStudent: student. student addCourse: course. student addGrade:'CS2335' value: 90.0. student addGrade: 'CS2335' value: 80.0. student addGrade: 'CS2335' value: 70.0. student addGrade: 'CS2335' value: 85.0. student := Student new. student name: 'Sally'. course addStudent: student. student addCourse: course. student addGrade:'CS2335' value: 60.0. student addGrade: 'CS2335' value: 50.0. student addGrade: 'CS2335' value: 40.0. student addGrade: 'CS2335' value: 55.0. testStudentAverage course studentAverageFor: 'Bob'. course studentAverageFor: 'Sally'. course classAverage. initialize "Initialize a newly created instance. This method must answer the receiver." " *** Edit the following to properly initialize instance variables ***" student := nil. course := nil. " *** And replace this comment with additional initialization code *** " ^self