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

Recommended Answers

All 2 Replies

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

Also, never throw exceptions from main().

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.