So, I have multiple classes modeling a university. I have Student which has subclasses GradStudent and UndergradStudent. I also have a course class. I am having issues figuring out what to pass to add and drop students and to add and remove courses.
I keep getting errors like this:
./Student.java:39: cannot find symbol
symbol : variable student
location: class Student
if (course.removeStudent(student)) {
^
^
./GradStudent.java:23: cannot find symbol
symbol : variable student
location: class GradStudent
if(course.getNumber() >= 5000 && numCoursesEnrolled < maxCourses && course.addStudent(student)) {
If someone could help, I would really appreciate it!
Here are my classes:
public abstract class Student extends Person {
protected Course[] courses;
protected final int maxCourses = 4;
protected int numCoursesEnrolled;
protected double gpa;
public Student(String name, int UFID, String dob, double gpa) {
super(name, UFID, dob);
this.gpa = gpa;
courses = new Course[maxCourses];
numCoursesEnrolled = 0;
}
public Student(String name, int UFID, String dob, double gpa, Course[] courses) {
super(name, UFID, dob);
this.gpa = gpa;
this.courses = courses;
for(int i=0; i<courses.length; i++) {
if (courses[i] != null)
numCoursesEnrolled++;
}
}
public int getNumCoursesEnrolled() {
return numCoursesEnrolled;
}
public void setNumCoursesEnrolled(int numCoursesEnrolled) {
this.numCoursesEnrolled = numCoursesEnrolled;
}
public double getGpa() {
return gpa;
}
public void setGpa(double gpa) {
this.gpa = gpa;
}
public abstract boolean addCourse(Course course);
public boolean dropCourse(Course course) {
if (course.removeStudent(student)) {
for(int i=0; i<courses.length; i++) {
if(courses[i] == course)
courses[i] = null;
}
numCoursesEnrolled--;
return true;
}
else return false;
}
public String toString() {
String s = super.toString() + "\nGPA: " + gpa + "\nCourses enrolled in: " + Course.toString();
for(int i=0; i<courses.length; i++) {
s += "Course " + i + ":\n" + courses[i].toString();
}
return s;
}
}
public class Course {
private String type;
private String title;
private int number;
private int numCredits;
private Instructor instructor;
private GradStudent[] TAs;
private Student[] students;
private int capacity;
private int currentEnrollment;
public Course(String type, int number, String title, int numCredits) {
this.type = type;
this.number = number;
this.title = title;
this.numCredits = numCredits;
}
public Course(String type, int number, String title, int numCredits,
Instructor instructor, GradStudent[] TAs, int capacity) {
this(type, number, title, numCredits);
this.instructor = instructor;
this.TAs = TAs;
students = new Student[capacity];
currentEnrollment = 0;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public int getNumber() {
return number;
}
public void setNumber(int number) {
this.number = number;
}
public int getNumCredits() {
return numCredits;
}
public void setNumCredits(int numCredits) {
this.numCredits = numCredits;
}
public int getCapacity() {
return capacity;
}
public void setCapacity(int capacity) {
Student[] students1 = new Student[capacity];
for(int i=0; i<students.length; i++)
students1[i] = students[i];
students = students1;
}
public int getCurrentEnrollment() {
return currentEnrollment;
}
public void setCurrentEnrollment(int currentEnrollment) {
this.currentEnrollment = currentEnrollment;
}
public Student[] getStudents() {
return students;
}
public void setStudents(Student[] students) {
this.students = students;
}
public Instructor getInstructors() {
return instructor;
}
public void setInstructors(Instructor instructor) { //set course variable as well
this.instructor = instructor;
}
public GradStudent[] getTAs() {
return TAs;
}
public void setTAs(GradStudent[] TAs) {
this.TAs = TAs;
}
public boolean addStudent(Student student) {
if(currentEnrollment < capacity) {
students[currentEnrollment] = student;
currentEnrollment++;
return true;
}
else return false;
}
public boolean removeStudent(Student student) {
for(int i=0; i<students.length; i++) {
if(students[i].equals(student)) {
students[i] = null;
--currentEnrollment;
return true;
}
}
return false;
}
public String toString() {
String s = "Course Info: " + type + number + "\nTitle: " + title + "\nInstructor: " + instructor.getName() + "\nTAs: ";
for(int i=0; i<TAs.length; i++) {
s += "\n" + TAs[i].getName();
}
s += "\nNumber Of Students: " + currentEnrollment + "\nCapacity: " + capacity;
return s;
}
}
And related methods:
//Gradstudent
public boolean addCourse(Course course) {
if(course.getNumber() >= 5000 && numCoursesEnrolled < maxCourses && course.addStudent(student)) {
for(int i=0; i<courses.length; i++) {
if(courses[i] == null) {
courses[i] = course;
break;
}
}
numCoursesEnrolled++;
return true;
}
else return false;
}
//undergrad
public boolean addCourse(Course course) {
if(course.getNumber() < 5000 && numCoursesEnrolled < maxCourses && course.addStudent()) {
for(int i=0; i<courses.length; i++) {
if(courses[i] == null) {
courses[i] = course;
break;
}
numCoursesEnrolled++;
}
return true;
}
else return false;
}