Hey am back...this time am sending the entire code...please have a look see and tell what am doing wrong.Tried your suggestion and it still didn't work. 3 classes....please note: the Student class is supposed to have the result (as a Result object) of the students on the module,
public class Student {
String studentName;
String bannerID;
double courseworkMark;
double examMark;
double totalScore;
Result result;
public Student(String studentName, String bannerID,double courseworkMark, double examMark){
this.studentName=studentName;
this.bannerID=bannerID;
this.courseworkMark=courseworkMark;
this.examMark=examMark;
}
public String getGrade(){
return result.getGrade();
}
public String getResult(){
return result.getResult();
}
public double getTotalScore(){
return result.getTotalScore();
}
public String toString(){
String studentDetails = new String();
studentDetails+=String.format("%-20s%20s%20s%20s%20s%20s%20s\n", this.studentName, this.bannerID,this.courseworkMark,this.examMark,this.totalScore,this.getGrade(),this.getResult());
return r;
}
}
//Result class
public class Result {
private double courseworkMark;
private double examMark;
private double totalMark;
private double overallMark;
String grade;
String moduleResult;
public Result(double courseworkMark, double examMark){
this.courseworkMark=courseworkMark;
this.examMark=examMark;
}
public String getGrade(){
this.overallMark=this.courseworkMark+this.examMark;
totalMark=this.overallMark/2;
if (totalMark >= 69.5){
grade="A";
if(totalMark>= 59.5 && overallMark < 69.5)
grade="B1";
if (totalMark >= 49.5 && totalMark < 59.5)
grade="B2";
if (totalMark >=40 && totalMark < 49.5)
grade="C";
if (totalMark >=29.5 && totalMark < 40)
grade = "D";
} else {
grade ="E";
}
return grade;
}
public String getResult(){
overallMark=courseworkMark+examMark;
totalMark=overallMark/2;
if(totalMark>=39.5 || courseworkMark >= 30 && examMark >= 30){
moduleResult= "PASS";
if(courseworkMark < 40 && examMark <40)
moduleResult ="RB2";
if (examMark < 40 && courseworkMark > 40)
moduleResult = "RC2";
if (courseworkMark < 40 && examMark > 40)
moduleResult = "RE2";
}
return moduleResult;
}
public double getTotalScore(){
return totalMark;
}
public double getCourseworkMark(){
return courseworkMark;
}
public double getExamMark(){
return examMark;
}
}
//Module class
public class Module {
Student [] students; //Array of Student objects
//Module Details
String moduleName;
double courseworkContribution= 0.6F; //coursework contributes 60% of overallMark
double examContribution=0.4F; //exam contributes 40% of overallMark
int MAX_NUM_OF_STUDENTS;
double courseworkAverage;
double examAverage;
double overallMarkAverage;
public Module(int MAX_NUM_OF_STUDENTS){ //constructor for creating objects of type Module
this.students = new Student[MAX_NUM_OF_STUDENTS];
}
public void addStudent(String studentName, String bannerID, double courseworkMark,double examMark){
this.students[this.MAX_NUM_OF_STUDENTS] = new Student(studentName, bannerID, courseworkMark,examMark);
}
public String toString(){
String studentDetails = new String();
studentDetails+=String.format("%-20s%20s%20s%20s%20s%20s%20s", "STUDENT NAME","BANNER ID", "CWRK(60)", "EXAM (40)", "TOTAL", "GRADE", "RESULT")+"\n";
for (int count=0; count<MAX_NUM_OF_STUDENTS; count++){
this.students[count].getGrade();
this.students[count].getResult();
this.students[count].getTotalScore();
studentDetails+=this.students[count].toString()+"\n";
}
return studentDetails;
}
}
//Test class
public class
Test {
public static void main(String[]args) {
final int MAX_NUM_OF_STUDENTS=10;
Module md = new Module(MAX_NUM_OF_STUDENTS);
md.addStudent("Anderson Alan", "b0024545", 80,70);
md.addStudent("Brown Bill", "b94939939", 60,40);
md.addStudent("Carew Catherine", "B04993993", 59,69);
System.out.println(md);
}
}