Answered step by step
Verified Expert Solution
Link Copied!

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 13 File I/O 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 NUM_SCORES =4;
// named constant for the number of scores per student in file
public static void main(String[] 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:
trash/trash
Unable to open file: trash/trash
Enter name of output file to create:
gradeAvg.txt
Average grades saved to gradeAvg.txt
> cat grades.txt
Biden 85909598
Trump 50707580
Obama 90959897
Bush 80707585
Clinton 90958599
Bush 85959094
> cat gradeAvg.txt
Here are the average grades:
Biden 92.0
Trump 68.8
Obama 95.0
Bush 77.5
Clinton 92.3
Bush 91.0
> 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 1 name followed by 4 numbers on each line,
separated by spaces. The following error was generated:
4 scores should follow each name, with spaces in between.
Grades could not be averaged.
> cat badformat.txt
Biden 8590
Trump 507075
Obama 90959897
Bush 80707585
Clinton 90958599Bush 85959094
*/
badformat.txt - Biden 8590
Trump 507075
Obama 90959897
Bush 80707585
Clinton 90958599Bush 85959094
grades.txt - Biden 85909598
Trump 50707580
Obama 90959897
Bush 80707585
Clinton 90958599
Bush 85959094
image text in transcribed

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

Database Systems Design Implementation And Management

Authors: Carlos Coronel, Steven Morris

14th Edition

978-0357673034

More Books

Students also viewed these Databases questions