<?xml version="1.0"?>

<st-source>
<time-stamp>From VisualWorks® NonCommercial, 7.4.1 of May 30, 2006 on October 31, 2006 at 10:26:45 am</time-stamp>
<!-- Package Refactor Exercise* -->


<name-space>
<name>RefactoringExercise</name>
<environment>Smalltalk</environment>
<private>false</private>
<imports>
			private Smalltalk.*
			</imports>
<category>Refactor Exercise</category>
<attributes>
<package>Refactor Exercise</package>
</attributes>
</name-space>

<class>
<name>Course</name>
<environment>RefactoringExercise</environment>
<super>Core.Object</super>
<private>false</private>
<indexed-type>none</indexed-type>
<inst-vars>id students </inst-vars>
<class-inst-vars></class-inst-vars>
<imports></imports>
<category>Refactor Exercise</category>
<attributes>
<package>Refactor Exercise</package>
</attributes>
</class>

<comment>
<class-id>RefactoringExercise.Course</class-id>
<body>Some COmment</body>
</comment>

<class>
<name>StudentTest</name>
<environment>RefactoringExercise</environment>
<super>XProgramming.SUnit.TestCase</super>
<private>false</private>
<indexed-type>none</indexed-type>
<inst-vars>student course </inst-vars>
<class-inst-vars></class-inst-vars>
<imports></imports>
<category>Refactor Exercise</category>
<attributes>
<package>Refactor Exercise</package>
</attributes>
</class>

<class>
<name>Student</name>
<environment>RefactoringExercise</environment>
<super>Core.Object</super>
<private>false</private>
<indexed-type>none</indexed-type>
<inst-vars>courses name </inst-vars>
<class-inst-vars></class-inst-vars>
<imports></imports>
<category>Refactor Exercise</category>
<attributes>
<package>Refactor Exercise</package>
</attributes>
</class>





<methods>
<class-id>RefactoringExercise.Course class</class-id> <category>instance creation</category>

<body package="Refactor Exercise" selector="new">new
	"Answer a newly created and initialized instance."

	^super new initialize</body>
</methods>


<methods>
<class-id>RefactoringExercise.Course</class-id> <category>initialize-release</category>

<body package="Refactor Exercise" selector="initialize">initialize
	"Initialize a newly created instance. This method must answer the receiver."
	id := nil.
	students := OrderedCollection new.
	^self</body>
</methods>

<methods>
<class-id>RefactoringExercise.Course</class-id> <category>calculation</category>

<body package="Refactor Exercise" selector="classAverage">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.</body>

<body package="Refactor Exercise" selector="studentAverageFor:">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.</body>
</methods>

<methods>
<class-id>RefactoringExercise.Course</class-id> <category>accessing</category>

<body package="Refactor Exercise" selector="addStudent:">addStudent: aStudent
	students add: aStudent</body>

<body package="Refactor Exercise" selector="id">id
	^id</body>

<body package="Refactor Exercise" selector="id:">id: anObject
	id := anObject</body>

<body package="Refactor Exercise" selector="students">students
	^students</body>
</methods>


<methods>
<class-id>RefactoringExercise.Student class</class-id> <category>instance creation</category>

<body package="Refactor Exercise" selector="new">new
	"Answer a newly created and initialized instance."

	^super new initialize</body>
</methods>


<methods>
<class-id>RefactoringExercise.Student</class-id> <category>initialize-release</category>

<body package="Refactor Exercise" selector="initialize">initialize
	"Initialize a newly created instance. This method must answer the receiver."
	courses := Dictionary new.
	^self</body>
</methods>

<methods>
<class-id>RefactoringExercise.Student</class-id> <category>accessing</category>

<body package="Refactor Exercise" selector="gradesFor:">gradesFor: aCourseId
   ^courses at: aCourseId</body>

<body package="Refactor Exercise" selector="name">name
    ^name.</body>

<body package="Refactor Exercise" selector="name:">name: aString
	name:= aString.</body>

<body package="Refactor Exercise" selector="addGrade:value:">addGrade: aCourseId value:anInteger
	|grades|
      grades := courses at: aCourseId.
      grades add: anInteger.</body>

<body package="Refactor Exercise" selector="addCourse:">addCourse: aCourse
	courses at: aCourse id put: OrderedCollection new.</body>
</methods>


<methods>
<class-id>RefactoringExercise.StudentTest class</class-id> <category>instance creation</category>

<body package="Refactor Exercise" selector="new">new
	"Answer a newly created and initialized instance."

	^super new initialize</body>
</methods>


<methods>
<class-id>RefactoringExercise.StudentTest</class-id> <category>initialize-release</category>

<body package="Refactor Exercise" selector="setUp">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.</body>

<body package="Refactor Exercise" selector="testStudentAverage">testStudentAverage
     course studentAverageFor: 'Bob'.
     course studentAverageFor: 'Sally'.
     course classAverage.</body>

<body package="Refactor Exercise" selector="initialize">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</body>
</methods>



</st-source>
