First problem
private ArrayList listOfStudents;
Since our book is the 2nd edition not the 4th, you need to write down the after the ArrayList! why? so the computer knows what type you are storing.
Second problem
When you run 'Admin', John's GPA doesn't stop. So I have to make it stop. It doesn't stop because the loop isn't fully coded.
I knew that it had to do with i++;
I knew that it had to do with i++;
int index =0;
while (index
{
System.out.print(seniors.getStudent(index).getName());
System.out.println(""+ " " + seniors.getStudent(index).getGPA());
index++;
And since the i value is index, you write index++;
yes it Compiled. I thought it would not compile because the two students had three courses. So I thought they would not recognize the fourth course.
seniors.add(new Student("Yejun"));
seniors.getStudent(2).addCourse(new Course ("English",99));
seniors.getStudent(2).addCourse(new Course ("Math",99));
seniors.getStudent(2).addCourse(new Course ("History",99));
seniors.getStudent(2).addCourse(new Course ("Band",100));
I think this should be private because then anyone would access and mess up the GPA.
public void setGPA()
{
int sum=0;
for(int i=0; i<courseList.size(); i++)
sum = sum+ (courseList.get(i).getGrade());
}
Part 2
thanks Michael... :P
4. The toString() method is inherited (from class Object) by class Student (all Java classes inherit from the Object class). What is the output when this method is called on a Student object?
public String toString()
{
String result = "";
for(int i=0; i
{
result = result + courseList.get(i).getCourseTitle() + ", ";
}
return name + ": " + result;
}
{
String result = "";
for(int i=0; i
{
result = result + courseList.get(i).getCourseTitle() + ", ";
}
return name + ": " + result;
}
5. Create a new field in StudentList named deansList that holds a list of students who are on the Dean's List. ( GPAs of 88 or higher.)
public String deanKids()
{
for(int i=0; i
{
if(listOfStudents.get(i).getGPA() >= 88)
{
deansList += listOfStudents.get(i).getName();
}
}
return deansList;
}
{
for(int i=0; i
{
if(listOfStudents.get(i).getGPA() >= 88)
{
deansList += listOfStudents.get(i).getName();
}
}
return deansList;
}
thanks Michael... :P
6. Create a method named printDeansList() that prints the names of students on the Deans List with their GPAs. Each student should be printed on a new line.
printdeansList()
public void printDean()
{
for(int i=0; i
{
if(listOfStudents.get(i).getGPA() >= 88)
{
System.out.println(listOfStudents.get(i).getName() + " " + listOfStudents.get(i).getGPA());
}
}
}
{
for(int i=0; i
{
if(listOfStudents.get(i).getGPA() >= 88)
{
System.out.println(listOfStudents.get(i).getName() + " " + listOfStudents.get(i).getGPA());
}
}
}
7. Create a method named findTopStudent() that finds the student with the highest GPA and prints..
(example) The top student is Mario with a GPA of 98
findTopStudent()
public void topStudent()
{
for(int i=1; i
{
if(listOfStudents.get(i).getGPA() >= listOfStudents.get(bestStudent).getGPA())
{
bestStudent = i;
}
}
System.out.println(listOfStudents.get(bestStudent));
}
System.out.println(listOfStudents.get(bestStudent));
}
{
for(int i=1; i
{
if(listOfStudents.get(i).getGPA() >= listOfStudents.get(bestStudent).getGPA())
{
bestStudent = i;
}
}
System.out.println(listOfStudents.get(bestStudent));
}
System.out.println(listOfStudents.get(bestStudent));
}
copyright to Michael..
No comments:
Post a Comment