Ex: If the input of the program is: StudentInfo.tsv and the contents of StudentInfo.tsv are: Barrett Bradshaw Charlton Mayo Stern Edan 70 45 59 Reagan 96 97 88 Caius 73 94 80 Tyrese 88 61 36 Brenda 90 86 45 the file report.txt should contain: Barrett Bradshaw Charlton Mayo Stern Edan 70 45 59 F Reagan 96 97 88 A Caius 73 94 80 B Tyrese 88 61 36 D Brenda 90 86 45 с Averages: Midterm1 83.40. Midterm2 76.60. Final 61.60

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

I need help fixing this java program below:

import java.util.Scanner;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.PrintWriter;
import java.io.IOException;

public class LabProgram {
   public static void main(String[] args) throws IOException {
      Scanner scnr = new Scanner(System.in);
      
      String fileName;
        String[] lastNames, firstNames;
        int[] midterm1, midterm2, finalScores;
        // Read a file name from the user and read the tsv file
        fileName = scnr.next();
        try (Scanner fileScanner = new Scanner(new FileInputStream(fileName))) {
            int numStudents = Integer.parseInt(fileScanner.nextLine());
            lastNames = new String[numStudents];
            firstNames = new String[numStudents];
            midterm1 = new int[numStudents];
            midterm2 = new int[numStudents];
            finalScores = new int[numStudents];
            for (int i = 0; i < numStudents; i++) {
                lastNames[i] = fileScanner.next();
                firstNames[i] = fileScanner.next();
                midterm1[i] = fileScanner.nextInt();
                midterm2[i] = fileScanner.nextInt();
                finalScores[i] = fileScanner.nextInt();
            }
        }
        // Compute student grades and exam averages, then output results to a text file
        try (PrintWriter outputFile = new PrintWriter(new FileOutputStream("report.txt"))) {
            for (int i = 0; i < lastNames.length; i++) {
                int average = (midterm1[i] + midterm2[i] + finalScores[i]) / 3;
                char letterGrade = getLetterGrade(average);
                outputFile.printf("%s %s %d %d %d %c%n", lastNames[i], firstNames[i],
                        midterm1[i], midterm2[i], finalScores[i], letterGrade);
            }
            double avgMidterm1 = calculateAverage(midterm1);
            double avgMidterm2 = calculateAverage(midterm2);
            double avgFinal = calculateAverage(finalScores);

            outputFile.printf("Averages: Midterm1 %.2f, Midterm2 %.2f, Final %.2f%n", avgMidterm1, avgMidterm2, avgFinal);
        }
    }

    private static char getLetterGrade(int average) {
        if (average >= 90) {
            return 'A';
        } else if (average >= 80) {
            return 'B';
        } else if (average >= 70) {
            return 'C';
        } else if (average >= 60) {
            return 'D';
        } else {
            return 'F';
        }
    }

    private static double calculateAverage(int[] array) {
        int sum = 0;
        for (int value : array) {
            sum += value;
        }
        return (double) sum / array.length;
    }
}

 

It said this:

Could not find file: report.txt Exception in thread "main" java.lang.NumberFormatException: For input string: "Barrett Edan 70 45 59" at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) at java.base/java.lang.Integer.parseInt(Integer.java:652) at java.base/java.lang.Integer.parseInt(Integer.java:770) at LabProgram.main(LabProgram.java:17)

Ex: If the input of the program is:
StudentInfo.tsv
and the contents of StudentInfo.tsv are:
Barrett
Bradshaw
Charlton
Mayo
Stern
Barrett
Bradshaw
Charlton
Edan
70 45 59
Reagan 96 97 88
Caius 73 94 80
the file report.txt should contain:
Mayo
Stern
Tyrese 88 61 36
Brenda 90 86 45
Edan
70 45 59 F
Reagan 96 97 88 A
Caius 73 94 80 B
Tyrese 88 61 36 D
Brenda 90 86 45 с
Averages: Midterm1 83.40, Midterm2 76.60, Final 61.60
Transcribed Image Text:Ex: If the input of the program is: StudentInfo.tsv and the contents of StudentInfo.tsv are: Barrett Bradshaw Charlton Mayo Stern Barrett Bradshaw Charlton Edan 70 45 59 Reagan 96 97 88 Caius 73 94 80 the file report.txt should contain: Mayo Stern Tyrese 88 61 36 Brenda 90 86 45 Edan 70 45 59 F Reagan 96 97 88 A Caius 73 94 80 B Tyrese 88 61 36 D Brenda 90 86 45 с Averages: Midterm1 83.40, Midterm2 76.60, Final 61.60
Expert Solution
steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Knowledge Booster
File Input and Output Operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education