java.lang.ArrayIndexOutOfBoundsException エラーが発生しています。
public class Trainee implements EvaluationDetails
{
private int traineeId;
private String traineeName;
private double traineeMarks[];
public Trainee(int id,String name,double Marks[])
{
traineeId=id;
traineeName=name;
traineeMarks=Marks;
}
public int getTraineeId()
{
return traineeId;
}
public String getTraineeName()
{
return traineeName;
}
public boolean validateTraineeMarks()
{
if(noOfCourses>0 && noOfCourses<8)
{
for(int i=0;i<=traineeMarks.length;i++)
{
if(traineeMarks[i]>0 && traineeMarks[i]<100)
continue;
else
return false;
}
return true;
}
else
return false;
}
public double calculateGPA()
{
int GPA;
int Cp[]=new int[7];
boolean bool=validateTraineeMarks();
if(bool==true)
{
for(int i=0;i<traineeMarks.length;i++)
{
if(traineeMarks[i]>=85 && traineeMarks[i]<=100)
Cp[i] = 5;
else if(traineeMarks[i]>=65 && traineeMarks[i]<85)
Cp[i] = 4;
else if(traineeMarks[i]>=0 && traineeMarks[i]<=65)
Cp[i] = 3;
}
GPA = //GPA calculation logic
}
else
{
System.out.println("Improper values for trainee marks");
return 0.0;
}
return GPA;
}
}
主なクラスは次のとおりです。
public class Demo {
public static void main(String[] args)
{
double marks[]={74.0,57.0,86.0,93.0,56.0,73.5,83.0};
Trainee t = new Trainee(102,"Dixon",marks);
System.out.println("Trainee Id:"+t.getTraineeId());
System.out.println("Trainee Name:"+t.getTraineeName());
System.out.println("GPA is"+t.calculateGPA());
}
}
インターフェイスは次のようにコーディングされます。
public interface EvaluationDetails
{
int creditpoints[]={3,3,4,4,2,3,5};
int noOfCourses=7;
public double calculateGPA();
}