Course - int i = findStudent(s.getSsn()); if (i != -1)...

Info iconThis 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;
Background image of page 1

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

View Full DocumentRight Arrow Icon
Background 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

Page1 / 2

Course - int i = findStudent(s.getSsn()); if (i != -1)...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online