diff --git a/338/homework5/School.java b/338/homework5/School.java index 812bcbf..275b671 100644 --- a/338/homework5/School.java +++ b/338/homework5/School.java @@ -93,16 +93,7 @@ public class School { return true; } - public int courseEnrolled(int id) { - // Helper function which simply counts up how many people are enrolled in a given cuorse - int count = 0; - for(Course i : this.courseList) { - if(i.id == id) { - count++; - } - } - return count; - } + public String getInstructor(int id) { // find the instructor name given an id @@ -131,7 +122,17 @@ public class School { return sum / (float)count; } - + public int courseEnrolled(int id) { + int count = 0; + for(Student s : this.studentList) { + // everytime a student has the given id in their grades add 1 to the counter + if(s.grades.get(id) != null) { + count++; + } + } + return count; + } + public void courseInfo(int id) { boolean found = false; // look for the course given by the id @@ -168,18 +169,24 @@ public class School { public boolean courseEmpty(int courseID) { for(Student s : this.studentList) { if(s.grades.get(courseID) != null) { - return true; + return false; } } return true; } public boolean deleteCourse(int id) { - for(int i =0;i