{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Course - int i = findStudent(s.getSsn if(i!=-1 return false...

Info icon This preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
public class Course { private String name; private String courseNo; private int maxStudents; private int numStudents = 0; private Student [] students; private double [] grades; public String getName() { return name;} public String setName(String name) { this.name = name;} public getCourseNo(){ return courseNo;} public setCourseNo( String cno) {courseNo = cno;} public getMaxStudents(){ return maxStudents;} public setMaxStudents( int n) { if( n>0) maxStudents = n;} public getNumStudents() return numStudents; } public Student[] getStudents() {return students;} public double[] getGrade() { return grades;} public Course() { this(""); } public Course(String name) { this.name = name; } public Course( String cno, String name, int capacity ) { courseNo = cno; this.name = name; maxStudents = capacity; students = new Student[capacity]; grades = new double [capacity]; } public boolean addStudent(Student s) { if (numStudents == maxStudents ) return false;
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: int i = findStudent(s.getSsn()); if (i != -1) return false; students[numStudents] = s; numStudents++; return true; } private int findStudent(String ssn) { for(int i= 0; i<numStudents; i++) { if (students[i].getSsn().equals(ssn)) { return i; } } return -1; } public boolean setGrade(String ssn, double grade) { int i= findStudent(ssn); if (i == -1) return false; grades[i] = grade; return true; } public double getGrade(String ssn) { int i = findStudent(ssn) if(i==-1) return -1; return grades[i]; } public double getMeanGrade { double sum = 0; for(int i =0 ; i<numStudent; i++) { sum+= grades[i]; } if (numStudents !=0) { return sum/numStudents; } else return 0; } public String toString() { String ret = ""; ret = ret+courseNo+"\t"+name+"\t"+ numStudents+"\n"; for(int i = 0; i<numStudents; i++) { ret = ret +"\n"+students[i].getSsn()+ "\t"+ students[i].getName() +"\t"+ grades[i]; } return ret; } }...
View Full Document

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern