I have got it to give some sort of output, but now all it does it print the first name 1 time, second name 2 times and so on.
Student Grade Report by Russ Penning
Name: Billy Bob - Grade:
Name: Ma Reynolds - Grade:
Name: Ma Reynolds - Grade:
Name: Pa Reynolds - Grade:
Name: Pa Reynolds - Grade:
Name: Pa Reynolds - Grade:
Name: Sue Anne - Grade:
Name: Sue Anne - Grade:
Name: Sue Anne - Grade:
Name: Sue Anne - Grade:
Name: Uncle Mortimer - Grade:
Name: Uncle Mortimer - Grade:
Name: Uncle Mortimer - Grade:
Name: Uncle Mortimer - Grade:
Name: Uncle Mortimer - Grade:
I'm still not getting anything back from the called method. Updated code:
import java.io.*;
public class StudentGrades
{
public static void main(String args[]) throws Exception
{
String LETTER;
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.
int x;
x = 0;
final int LIMIT = SIZE;
String stuScoreString; // used to store what is read before changing to integer.
int stuScore = 0;
int pairsToCompare;
boolean switchOccurred;
boolean done;
double temp;
double totalGrade;
totalGrade = 0;
int y;
y = 0;
System.out.println("Student Grade Report by Russ Penning");
System.out.println();
// 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.
{
y++;
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;
}
x++;
}
pairsToCompare--;
}
while(x < 8)
{
totalGrade = (score[x] + totalGrade);
x++;
}
// Call calculateGrades method here
LETTER = calculateGrades(totalGrade);
x = 0;
while(x < y)
{
LETTER = "";
System.out.println("Name: " + stuName + " - Grade: " + LETTER);
x++;
}
}
br.close();
System.exit(0);
} // End of main() method.
// Write calculateGrades method here.
public static String calculateGrades(double totalGrade)
{
String letterGrade;
double gradeAvg;
gradeAvg = (totalGrade/8);
if(gradeAvg >= 90)
letterGrade = "A";
else if (gradeAvg >= 80)
letterGrade = "B";
else if (gradeAvg >= 70)
letterGrade = "C";
else if (gradeAvg >= 60)
letterGrade = "D";
else
letterGrade = "F";
return letterGrade;