954,545 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Drop and Add Students to Course

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;
	}
gatorgirl
Newbie Poster
2 posts since Feb 2012
Reputation Points: 10
Solved Threads: 0
 
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)) {

you want to remove the variable student, but you have no variable student in any scope that can be used by that method. either you create one locally in that method, you keep one as a variable in class scope, or you must pass one as a parameter to that method../GradStudent.java:23: cannot find symbol
symbol : variable student
location: class GradStudent
if(course.getNumber() >= 5000 && numCoursesEnrolled < maxCourses && course.addStudent(student)) {

you haven't provided the complete GradStudent class, but it looks to me like this is exact the same problem. at least it is clear that in the method scope, you don't declare/instantiate a student variable.

stultuske
Posting Sensei
3,137 posts since Jan 2007
Reputation Points: 1,114
Solved Threads: 433
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: