Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Points Possible 100 Use TestScoreReader.java, TestAverages.java and Grades.csv 1.In TestScore Reader.java, create new method called getSum() to calculate the sur 2.In TestAverages.java, use getSum() to

image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
Points Possible 100 Use TestScoreReader.java, TestAverages.java and Grades.csv 1.In TestScore Reader.java, create new method called getSum() to calculate the sur 2.In TestAverages.java, use getSum() to print the students' scores sumOutput: Average for student # 1 is 86.6 Average for student # 2 is 78.8 Average for student # 3 is 90.4 Average for student # 4 is 72.0 Average for student # 5 is 83.4 No more scores. Sum for student # 1 is 433.0 Sum for student # 2 is 394.0 Sum for student # 3 is 452.0 Sum for student # 4 is 360.0 Sum for student #5 is 417.0 No more scores. Grades.csv TestAverages.java TestScore Reader.java import java.io.*; import java.util.Scanner The TestScore Reader class reada test scores as tokens from a file and calculates the average of each line of scores. public class TestscoreReader { private Scanner inputPile; private String line; The constructor opens a file to read the grades from. #paran filename the file to open. public Test Score Reader(String filename) throws IOException File file = new File(filename); inputFile = new Scanner (file); The readNextLine method reads the next line from the file. Breturn true if the line was read, false otherwise. public boolean readNextLine() throws IOException boolean lineRead; // Flag variable // Determine whether there is more to read. line Read - input file.hasNext(); 1/ If so, read the next line. if (line Read) line - inputPile.nextLine(); return lineRead; > / The getAverage method calculates the average of the last set of test enrered from the file Grades (1).csv Grades.csv boolean lineRead: 1/ Flag variable // Determine whether there is more to read. lineRead = InputFile.hanNext(); // If no, read the next line. if (line Read) line - InputFile.nextLine() return lineRoadt ) The getAverage method calculates the average of the last set of test scores read from the file. return the average. . public double getAverage() int total - 0; // Accumulator double average; // The average test score // Tokenize the last line read from the file. String[tokens - line.split(""); // Calculate the total of the test scores. for (String str : tokens) { total +- Integer.parseInt(str); 3 1/ Calculate the average of the scores. // Use a cast to avoid integer division. average - (double) total / tokens.length; // Return the average. return average; } / The close method closes the file. */ public void close() throws IOException inputFile.close(); ) Grades (1).csv Grades.csv import java.io.*; // Needed for IOException /** This program uses the Test ScoreReader class to read test scores from a file and get their averages. */ public class TestAverages { public static void main(String[] args) throws IOException { double average; // Test average int studentNumber = 1; // Control variable // Create a TestScoreReader object. Test ScoreReader scoreReader = new TestScoreReader("Grades.csv"); // Display the averages. while (scoreReader.readNextLine()) { 1/ Get the average from the Test ScoreReader. average = scoreReader.getAverage(); + // Display the student's average. System.out.println("Average for student studentNumber + average); is - // Increment the student number. student Number++; } // Close the Test ScoreReader. scoreReader.close(); System.out.println("No more scores."); } } Grades (3) 87 79 91 82 94 72 79 81 74 88 94 92 81 89 96 77 56 67 81 79 79 82 85 81 90

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

Step: 3

blur-text-image

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

Intelligent Databases Object Oriented Deductive Hypermedia Technologies

Authors: Kamran Parsaye, Mark Chignell, Setrag Khoshafian, Harry Wong

1st Edition

0471503452, 978-0471503453

Students also viewed these Databases questions