0

Okay so I'm supposed to read in grades from a file add them together and get the average the letter grade the minimum grade and the maximum...no setting variables to the read in...and the sentinel is -1 at the end of the sequence...I'm a bet messed up...this is what i have so far

import java.io.*;
import java.util.*;


public class Grader
{


static final int SENTINEL = -1;


public static void main(String[] args) throws
FileNotFoundException
{
Scanner inFile=
new Scanner(new FileReader("scores.dat"));
PrintWriter outFile = new
PrintWriter("scores.out");



//declare variables
int num;
int score;
int max;
int min;
char grade;


//receives information from file
num = inFile.nextInt();


if (num != SENTINEL)
do
{
score = 0;
num = inFile.nextInt();
score = score+num;
} while (num != SENTINEL);


if (score > 100)
System.out.println("Invalid data value. Program exiting...");


if ((score/10) >= 90)
grade = 'A';
else if ((score/10) >= 80 && (score/10)< 90)
grade = 'B';
else if ((score/10) >= 70 && (score/10)< 80)
grade = 'C';
else if ((score/10) >= 60 && (score/10)< 70)
grade = 'D';
else if ((score/10) < 60 && (score/10) > 0)
grade = 'F';
else
System.out.print("Error");


System.out.println(score);



inFile.close();
outFile.close();


}
}

help

Edited by happygeek: fixed formatting

3
Contributors
2
Replies
3
Views
9 Years
Discussion Span
Last Post by Ezzaral
0

For start, you declared SENTINEL to be a constant so it will never change

static final int SENTINEL = -1;

Secondly, if I interpreted your statement correctly you expect this variable have different value on the end. The value will not change even if you remove final from its declaration, SENTINEL stays as -1, because there are no changes to it in your program

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.