Non-static method cannot be referenced from a static context
Hi everybody!
I am currently studying Java at uni, and working on my assignment. Everything was going good, until I got stuck :(
I am supposed to produce a student enrolment system which allows students to be enrolled into courses, units, it also allows creating new students/courses/units and modifying all of them.
I have 4 classes so far:
CourseAdmin (Main Class), Course, Student, Unit.
Basically what I am trying to do is get the unitList ArrayList from the main (CourseAdmin) class, check if the particular student has any spare unit slots, check if the unit name supplied matched a unit in the uniList in the CourseAdmin class and if all of these are good, then enrol the student in the unit matching the unit code supplied
The method, which I got stuck on is in Student class - here's the code:
Code:
//-------------------------------------------------------------------------------------
//Enrolls a student into a unit, checking if the student has at least 1 empty
//slot in the enrolledUnits array and then checking if the unitCode supplied
//matched the unitCode of a unit in the CourseAdmin class
//If error occurs - the method will inform the user
public void enrollInUnit(String unitCode)
{
int i = 0; //For student's unitList
int i2 = 0; //for Enrollment system's unitList
while(i <= (enrolledUnits.length - 1) && enrolledUnits[i] != null)
{
i++;
}
while(!CourseAdmin.getUnitList().get(i2).getUnitCode().equals(unitCode) &&
i2 <= CourseAdmin.getUnitList().size())
{
i2++;
}
//Makes sure that there is at least 1 empty unit slot for the unit
if(enrolledUnits[i] == null)
{
if(CourseAdmin.getUnitList().get(i2).getUnitCode().equals(unitCode))
enrolledUnits[i] = CourseAdmin.getUnitList().get(i2);
else
System.out.println("No such unit in the database!");
}
else
System.out.println("This student is already enrolled into 4 units!");
}
//-------------------------------------------------------------------------------------
I also have a method in the CourseAdmin class, returning the unitList ArrayList
Code:
public ArrayList<Unit> getUnitList()
{
return unitList;
}
...and the Main method from the CourseAdmin
Code:
public static void main(String[] args)
{
CourseAdmin driver = new CourseAdmin();
driver.menu();
}