Below is the code for a program which stores the names and marks of 30 students into an array. I am having problems with the displayResults method. Any suggestions?
public class MScResults
{
public String namesIn;
public int studentNoin;
int totalNoOfStudents;
private static final int NOOFSTUDENTS = 30;
String[]names = new String[NOOFSTUDENTS];
float [] marks= new float [NOOFSTUDENTS];
int[] studentNo = new int [NOOFSTUDENTS];
public MScResults()
{
}
public int setNames(int studentNoin, String namesIn)
{
if(studentNoin >=1 &&studentNoin <= 30)
{
names[studentNoin-1] = namesIn;
return 1;
}
else
{
return 0;
}
}
public int storeMark(int studentNoin, float markObtained)
{
if(studentNoin >=1 &&studentNoin <= 30)
{
marks[studentNoin-1] = markObtained;
return -1 ;
}
else
{
return -9;
}
}
public int getNoOfStudents(float mark1, float mark2)
{
int totalStudents= 0;
for(int i =0; i<=NOOFSTUDENTS; i++)
{
if(marks[i] <= mark1 && marks[i] >= mark2)
return totalStudents= totalStudents +1;
else if (marks[i] <= mark2 && marks[i] >= mark1)
return totalStudents = totalStudents + 1;
}
return totalStudents;
}
public float getMark(int idNo)
{
if (idNo >=1 && idNo <=30)
{
return marks[idNo-1];
}
else
{
return -9;
}
}
public void displayHighestMark()
{
int c=0;
int highMarkIndex=0;
float highestMark=0;
while(c<30)
{
if (marks[c]> highestMark)
{
highestMark = marks[c];
highMarkIndex=c;
}
c++;
}
System.out.println("Highes
t mark achieved is "+highestMark+" by "+names[highMarkIndex]);
}
public void displayLowestMark()
{
int c=0;
int lowMarkIndex=0;
float lowestMark=0;
while (c<30)
{
if(marks[c]<lowestMark)
{
lowestMark = marks[c];
lowMarkIndex=c;
}
c++;
}
System.out.println("Lowest
mark achieved is "+lowestMark+" by "+names[lowMarkIndex]);
}
public float getAverageMark()
{
float average = 0;
float sum = 0;
for(int i=0; i<marks.length;i++)
{
sum = sum+marks[i];
average = sum/30;
}
return average;
}
public void displayResults()
{
char grade= ' ';
System.out.println(" MSc Results: School of MIS ");
System.out.println("Studen
t Name\tPercentage Mark\tStatus/GRADE");
System.out.println("------
----------
----------
----------
-------");
for(int i =0; i<=NOOFSTUDENTS; i++);
{
System.out.println(" "+names+"\t"+marks+"\t" +grade);
}
if(marks[i]> 69.5)
{
System.out.println("you have obtained a distinction");
}
if(marks[i] >= 59.5 && marks[i]<=69.4)
{
System.out.println("you have obtained a merit");
}
if(marks[i] >=39.5 && marks[i] <=59.4)
{
System.out.println("you have obtained a pass");}
else
{
if(marks[i] <39.5)
{
System.out.println(" you have failed");
}
}
}
}
and here are the errors....
----jGRASP exec: J:\jdk1.3\bin\javac H:\Java assignment\MScResults.java
H:\Java assignment\MScResults.java
:135: cannot resolve symbol
symbol : variable i
location: class MScResults
if(marks[i]> 69.5)
^
H:\Java assignment\MScResults.java
:139: cannot resolve symbol
symbol : variable i
location: class MScResults
if(marks[i] >= 59.5 && marks[i]<=69.4)
^
H:\Java assignment\MScResults.java
:139: cannot resolve symbol
symbol : variable i
location: class MScResults
if(marks[i] >= 59.5 && marks[i]<=69.4)
^
H:\Java assignment\MScResults.java
:143: cannot resolve symbol
symbol : variable i
location: class MScResults
if(marks[i] >=39.5 && marks[i] <=59.4)
^
H:\Java assignment\MScResults.java
:143: cannot resolve symbol
symbol : variable i
location: class MScResults
if(marks[i] >=39.5 && marks[i] <=59.4)
^
H:\Java assignment\MScResults.java
:148: cannot resolve symbol
symbol : variable i
location: class MScResults
if(marks[i] <39.5)
^
6 errors