Answered step by step
Verified Expert Solution
Question
1 Approved Answer
/ * Starter project for Assignment 1 3 File I / O for Grade Average Your job is to write a program to read the
Starter project for Assignment File IO for Grade Average
Your job is to write a program to read the grades.txt file
in this project, to produce output like shown here.
"grades.txt is the file your program should read. "badformat.txt is an example of a file that your program can't read, so a clear error message should be generated, as shown in the sample output.
import java.io;
import java.util.Scanner;
class Main
private static final int NUMSCORES ;
named constant for the number of scores per student in file
public static void mainString args
Sample Output on Repl, hills, or other Linux
specifying an invalid path will throw an exception:
Remember that "cat" is a Linux command to display the
contents of a text file on the screen.
Welcome to the Grade Average Calculator.
Please enter the name of a file to input:
trash
Unable to open file: trash
Please enter the name of a file to input:
grades.txt
Enter name of output file to create:
trashtrash
Unable to open file: trashtrash
Enter name of output file to create:
gradeAvg.txt
Average grades saved to gradeAvg.txt
cat grades.txt
Biden
Trump
Obama
Bush
Clinton
Bush
cat gradeAvg.txt
Here are the average grades:
Biden
Trump
Obama
Bush
Clinton
Bush
java Main
Welcome to the Grade Average Calculator.
Please enter the name of a file to input:
badformat.txt
Enter name of output file to create:
gradeAvg.txt
The file badformat.txt isn't in the right format:
it should have name followed by numbers on each line,
separated by spaces. The following error was generated:
scores should follow each name, with spaces in between.
Grades could not be averaged.
cat badformat.txt
Biden
Trump
Obama
Bush
Clinton Bush
badformat.txt Biden
Trump
Obama
Bush
Clinton Bush
grades.txt Biden
Trump
Obama
Bush
Clinton
Bush
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started