Sunday, October 17, 2010

Chapter 4 test

Part 1
1. Didn't finish, have doubts
2. Yes
3. int sumOfGrades = 0;
int numberOfCourses = 0;
for (Course subject : courseList)
{
sumOfGrades = sumOfGrades + subject.getGrade();
numberOfCrouse++;
}
GPA = sumOfGrades/numberOfCourses;
return GPA;
}
And this method should be public so that it can be accessed by the admin!

4. Returns the name of the object followed by the @ sign followed by a number.
public String toString()
{
String courses = "";
for (Course item : courseList)
{
courses = courses + ", " + item.getCourseTitle();
}

5.
public void makeDeansList()
{
for (Student person : listOfStudents)
{
if (person.getGPA() >= 88)
deansList.add(person);
}
}

6. public void printDeansList()
{
for (Student person : deansList)
{
System.out.println(person.getName());
}
}

7. public void findTopStudent()
{
Student topStudent = listOfStudents.get(0);
for (int i = 0; i <> topStudent.getGPA())
topStudent = listOfStudents.get(i);
}
System.out.println("The top student is "+topStudent.getName()+" with a GPA of "+topStudent.getGPA());
}





No comments:

Post a Comment