0

Trying to read a file from the user that contains numbers which i use to calculate avgs, range, number of #'s and so on. I can't get it to work tho. Any critiques and help would be much appreciated.

Thanks much

```
double grade; //variable for entered grades
double sum = 0; //the sum of the scores
double number = 0; //the number of scores calculated
double average; //the original avg of the scores
double rounded; //the avg rounded to two decimals
double highest; //highest score
double lowest; //lowest score
int aGds = 0; //number of A grades
int bGds = 0; //number of B grades
int cGds = 0; //number of C grades
int dGds = 0; //number of D grades
int fGds = 0; //number of F grades
int best = 0; //used for converting highest score to int
int worst = 0; //used for converting lowest score to int
String gradeFile; //string for file
Scanner scan = new Scanner(System.in);
System.out.println("Welcome to the Grade Calculator Program!");
System.out.println();
System.out.print("Please enter the name of the data file to process: ");
gradeFile = scan.nextLine();
Scanner input = new Scanner(new File(gradeFile));
highest = - Double.MAX_VALUE;
lowest = Double.MAX_VALUE;
while ((grade = input.hasNextDouble()) >= 0);
{
grade = scan.nextDouble();
sum = sum + grade;
number++;
if(grade >= 90)
aGds+=1;
else if(grade >= 80)
bGds+=1;
else if(grade >= 70)
cGds+=1;
else if(grade >= 60)
dGds+=1;
else if (grade <= 59)
fGds+=1;
if(grade > highest)
best = (int)(highest = grade);
if(grade < lowest)
worst = (int) (lowest = grade);
grade = scan.nextDouble();
}
}
input.close();
average = sum / number;
rounded = Math.round(average * 100.0) / 100.0;
System.out.println();
System.out.println("Grade Calculations:");
System.out.println("Total number of grades = " +number);
System.out.println("High score = " +best);
System.out.println("Low score = " +worst);
System.out.println("Average score = " +rounded);
System.out.println("Number of A's = " +aGds);
System.out.println("Number of B's = " +bGds);
System.out.println("Number of C's = " +cGds);
System.out.println("Number of D's = " +dGds);
System.out.println("Number of F's = " +fGds);
```

*Edited 3 Years Ago by Reverend Jim*: Fixed formatting