I'm fairly new to the java language but I can't seem to get my code to work. It is supposed to read an input file with names and 10 quiz scores for each person, then do a bubble sort until we have the top 8 scores, then create an average of those scores and give it a letter grade. The final output for each person is supposed to look like this:
Name: blah - Grade: B
The input file looks like this
and so on
Here's what my code looks like:
public class StudentGrades
public static void main(String args) throws Exception
final int SIZE = 10; // Number of quizzes
double score = new double[SIZE]; // Array used to store 10 quiz scores.
String stuName; // Used to store name.
x = 0;
final int LIMIT = SIZE;
String stuScoreString; // used to store what is read before changing to integer.
int stuScore = 0;
gradeAvg = 0;
totalGrade = 0;
y = 0;
System.out.println("Student Grade Report by Russ Penning");
// Start the input read.
FileReader fr = new FileReader("scores.dat");
BufferedReader br = new BufferedReader(fr);
// This is the work done in the fillArray() method
while((stuName = br.readLine()) != null) // Use to read only the first line of the array before change to integer.
x = 0;
done = false;
while(x < LIMIT)
// Place value in array.
stuScoreString = br.readLine();
// Convert String to integer.
stuScore = Integer.parseInt(stuScoreString);
score[x] = stuScore;
x++; // Get ready for next input item.
} // End of input loop.
stuScore = x - 2;
pairsToCompare = stuScore - 1;
// This is the work done in the sortArray() method
switchOccurred = true; // set flag to true
while(switchOccurred == true)
x = 0;
switchOccurred = false;
while(x < pairsToCompare)
if(score[x] > score[x + 1])
temp = score[x + 1];
score[x+1] = score[x];
score[x] = temp;
switchOccurred = true;
while(x < stuScore)
totalGrade = (score[x+2] + totalGrade);
gradeAvg = totalGrade / 8;
// Call calculateGrades method here
LETTER = calculateGrades(gradeAvg);
x = 0;
while(x < y)
LETTER = "";
System.out.println("Name: " + stuName + " - Grade: " + LETTER);
} // End of main() method.
// Write calculateGrades method here.
public static String calculateGrades(double gradeAvg)
if(gradeAvg >= 90)
LETTER = "A";
else if (gradeAvg >= 80)
LETTER = "B";
else if (gradeAvg >= 70)
LETTER = "C";
else if (gradeAvg >= 60)
LETTER = "D";
LETTER = "F";
} // End of StudentGrades class.
If anyone has any idea what is wrong with my code... Please let me know.