Question: // I need to store my grades in an array // I also need to figure out how to how to read a file with

// I need to store my grades in an array // I also need to figure out how to how to read a file with a list of grades as interger // the text file is called "grades.txt" import java.util.Scanner; import java.io.IOException; import java.io.FileReader; import java.io.BufferedReader; import java.util.Arrays; public class ExamStatistics{ //defining variables here String filename; int score; int A,B,C,D,F; int min,max, avg; public static void main(String[] args) { // using scanner and file reader to read the file name ExamStatistics ep = new ExamStatistics(); Scanner sc = new Scanner(System.in); System.out.println("Enter file name:"); ep.filename = sc.next(); int i=1; int t=0; try { BufferedReader br = new BufferedReader(new FileReader(ep.filename)); String sCurrentLine; while ((sCurrentLine = br.readLine()) != null) { if(i ==1) { t = Integer.parseInt(sCurrentLine); i =2; } else { ep.score = Integer.parseInt(sCurrentLine); if (ep.score >= 90) { ep.A++; } else if(ep.score >=80) { ep.B++; } else if(ep.score >=70) { ep.C++; } else if(ep.score >=60) { ep.D++; } else { ep.F++; } if( ep.min > ep.score) { ep.min = ep.score; } if( ep.max < ep.score) { ep.max = ep.score; } ep.avg = ep.avg + ep.score; } } } catch (IOException e) { e.printStackTrace(); } ep.avg = ep.avg / t; System.out.println("Minimum Score = " + ep.min); System.out.println("Maximum Score = " + ep.max); System.out.println("Average Score = " + ep.avg); System.out.println("A Score = " + ep.A); System.out.println("B Score = " + ep.B); System.out.println("C Score = " + ep.C); System.out.println("D Score = " + ep.D); System.out.println("F Score = " + ep.F); } // End Main // All other methods declared and implemented here ExamStatistics() { filename = "grades.txt"; score = 0; A=0; B =0; C =0; D=0; F=0; min =999; max =0; avg =0; } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!