Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

// 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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Big Data Concepts, Theories, And Applications

Authors: Shui Yu, Song Guo

1st Edition

3319277634, 9783319277639

More Books

Students also viewed these Databases questions

Question

What is digital literacy? Why is it necessary?

Answered: 1 week ago