i'm trying to call a method from a different class and i just cant get it to work....
code from method displayTutorGroup():
/**
* Displays the names and marks for the students
* in the tutor group in the Display Pane
*/
public void displayTutorGroup()
{
for (String name: this.students.keySet()) // line 1
{
System.out.println("Student " + name + ":"); // line 2
//this line should call the displayMarks() method from the class student, but whatever i try doesnt work
System.out.println();
}
}
Student Class code:
import java.util.*;
/**
* Class Student - Simple class representing an OU student and their marks
*
* @author M255 Course Team
* @version 1.0
*/
public class Student
{
/* instance variables */
private String name; // String representing student's name
private List<Integer> tmaMarks; // list of student's TMA marks.
private int examMark; // student's exam mark. -1 indicates exam has not been taken
private int substitutionScore; // student's substitution score. -1 if not yet calculated
private int finalOCAS; // final continuous assessment score. -1 if not yet calculated
/**
* Constructor for objects of class Student
*/
public Student(String aName)
{
// put your code here (see part (i))
name = aName;
List<Integer> tmaMarks = new ArrayList<Integer>();
examMark = -1;
substitutionScore = -1;
finalOCAS = -1;
}
/* instance methods */
/**
* Returns the integer average (rounded down) of the integers
* in the list given as the argument
*/
// put your code for the class method average() here (see part (iii)(a))
/**
* Returns the name of the receiver
*/
public String getName()
{
return this.name;
}
/**
* Sets the tmaMarks of the receiver to someTmaMarks
*/
public void setTmaMarks(List<Integer> someTmaMarks)
{
this.tmaMarks = someTmaMarks;
}
/**
* Returns the tmaMarks of the receiver
*/
public List<Integer> getTmaMarks()
{
return this.tmaMarks;
}
/**
* Sets the examMark of the receiver to aMark
*/
public void setExamMark (int aMark)
{
this.examMark = aMark;
}
/**
* Returns the examMark of the receiver
*/
public int getExamMark()
{
return this.examMark;
}
/**
* Sets the substitutionScore of the receiver to aScore
*/
private void setSubstitutionScore (int aScore)
{
this.substitutionScore = aScore;
}
/**
* Returns the substitutionScore of the receiver
*/
public int getSubstitutionScore()
{
return this.substitutionScore;
}
/**
* Sets the finalOCAS of the receiver to anOCAS
*/
private void setFinalOCAS (int anOCAS)
{
this.finalOCAS = anOCAS;
}
/**
* Returns the finalOCAS of the receiver
*/
public int getFinalOCAS()
{
return this.finalOCAS;
}
/**
* Displays the name and set of marks of the receiver
*/
public void displayMarks()
{
System.out.println("TMA marks are " + this.tmaMarks);
System.out.println("Exam mark is " + this.getExamMark());
System.out.println("Substitution score is " + this.getSubstitutionScore());
System.out.println("Final OCAS is " + this.getFinalOCAS());
}
/**
* Calculates and sets the substitutionScore of the receiver
*/
public void calcSubstitutionScore()
{
// put your code here (see part (iii)(b)
}
/**
* Calculates and sets the finalOCAS of the receiver
*/
public void calcFinalOCAS()
{
// put your code here (see part (iii)(c))
}
/**
* calculates the average
*/
public Integer average()
{
List<Integer> userData = new ArrayList<Integer>();
userData = this.getTmaMarks();
int total = 0;
for (int eachElement : userData)
{
total = total + eachElement;
}
int avg = ((int)total) / userData.size();
System.out.println("average = " + avg);
return avg;
}
}
i know this is something i should have learned early in the course but i cannot remember how to do it...can anyone help?