I'm working on a simple application which returns the student mark based on the particular module. My main issue is with the getModuleMark method, because I need it to return the module mark given the module index.
For the setModuleMark method I have passed both the index module and marks parameters in. I'm just getting a little confused as to what I need to put in the return for module marks.
At the moment when I run the application I get the following output:
Joe Bloggs
Module 0: 50.0
Module 1: 50.0
Module 7: 50.0
See code below:
public class Student {
public static void main(String[] args) {
Student student = new Student("Joe", "Bloggs");
// Add some marks to the student.
student.setModuleMark(0, 10);
student.setModuleMark(1, 80);
student.setModuleMark(7, 50);
// Display the marks.
System.out.println(student.getForename() + " " + student.getSurname());
System.out.println("Module 0: " + student.getModuleMark(0));
System.out.println("Module 1: " + student.getModuleMark(1));
System.out.println("Module 7: " + student.getModuleMark(7));
}
private String forename;
private String surname;
private double marks;
public Student(String forename, String surname) {
super();
this.forename = forename;
this.surname = surname;
double [] ModuleMark = new double [7]; //Creates array of fixed size 7
}
/**
* @return the forename
*/
public String getForename() {
return this.forename;
}
/**
* @return the surname
*/
public String getSurname() {
return this.surname;
}
/**
* @param marks the marks to set
* @param i
*/
public double getModuleMark (int in) {
return this.marks;
}
public void setModuleMark(int in, double marks) {
this.marks = marks;
}
}