The code below is supposed to add a student to the enrolledStudents
list after confirming they have registered (Registration occurs in Student
class)
My Student class contains the master list (studentRegistry), of all students
who have ever studied at the Training Center.
My Course class (of which this snippet is a part) attempts to verify a Student
has registered before enrolling them in their selected Course.
Each Course maintains a (sub)List of enrolled Students which contains only the
Students name and the reference (index) to their corresponding record in the
studentRegistry.
If the Student isn't yet registered, we will register them first (but since the
lookup is broken, I haven't bothered with this yet)
standardCharge is one of the Course fields, other fields (within the braces)
are derived
studentName is the unique identifier for Students
public void enrolStudent(int index, Student studentName) {
double standardCharge, rebate, priceRate, nettCharge;
int studentReference;
if (students.isEmpty())
index = 0;
else
index = students.size();
// lookup the Student
if (studentRegistry.contains(studentName))
studentReference = studentRegistry.indexOf(studentName);
else
studentRegistry.add(new Student(studentName));
// TODO Call applicable discounts and apply them
// this will provide the values for the fields below
nettCharge = (standardCharge - rebate) * priceRate;
// TODO Send the nettCharge back to Student.setCourseFees(nettCharge)
}
I keep getting an error that studentRegistry cannot be resolved.
Is this because I am trying to access the variable directly rather than creating something like:
In Student class
public int lookupStudent(String studentName){
if (studentRegistry.contains(studentName)) {
studentRef = studentRegistry.indexOf(studentName);
} else {
studentRegistry.add(new Student(studentName));
studentRef = studentRegistry.indexOf(studentName);
}
return studentRef;
}
(I think) I should then be able to utilize studentRef to access the other fields I need.