I’m a bit mixed up. Here is my work so far.
public class CourseYear
{
private String courseName;
private int year;
private String tutorName;
private String [] moduleList;
The moduleList is to hold 6 modules
public CourseYear()
{
courseName = "Default";
year = 0;
tutorName = "Joe Bloggs";
moduleList = new String [5];
}
This is where my problem lies, I’m not sure how to do the array parts:
public void addModule(Module newModule, int index)
{
Module = newModule[0];
Module = newModule[1];
Module = newModule[2];
Module = newModule[3];
Module = newModule[4];
Module = newModule[5];
}
I have no idea how to do the get methods
public Module getModule(int index)
{
return Module[index];
}
you need to reference your array with the index. In your class definition you need a
private Module[] modules = new Module[6]; // initializeIf you want your Array to contain
Moduleinstances, the array needs to be an array of Modules. Right now your class has aStringarray.and then your add method becomes
Note a few things:
1). Your array has 6 buckets, so the indexes allowed are 0-5. If index in the
addModulemethod is out of bounds you will get an exception.2).
addModuleexpectsnewModuleto be a module instance. So you use addModule likeYou can also use
addModuleinside theCourseYearclass. Say you want to initialize in your constructorYou should be able to figure out
getModule