Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Lab assignment pdf: Lab 5 - Grade Calculator.pdf Input text file for Lab 5: class1.txt Download : Jerry 86 Eric 97 Karen 90 Valerie 72

Lab assignment pdf: Lab 5 - Grade Calculator.pdf Input text file for Lab 5: class1.txt Download : Jerry 86 Eric 97 Karen 90 Valerie 72 Patricia 99 Jim 62 Han 80 Scott 94 Derek 0 Marilyn 88 Elyse 26 Arthur 89 Winni 88 Jessie 41 Addison 93 Homer 65 Max 17 Carmela 72 Briget 61 Bob 11 Blanca 63 Roseline 95 Kelly 100 Anastasia has a bunch of text files containing student first names and grades for her classes. She wants the grades automatically transformed into letter grades, along with the number of students in her class counted and their average grade totaled. These letter grades and averages she then wants saved into another file, but this one with no identifying information (i.e., no names). She could buy software to do it herself, but that’s costs money. Therefore, she’s asked you to write the program for her. She has an example class with fake students and grades inside a text file called class1.txt (download the file from the Lab Canvas page) which looks like the following: You can assume all grades are always integer values. She has also created a mockup of what she wants the application to look like. This application should take in the name of the file to be read in and the name of the file where the data can be saved to. Then, after the program processes the file, it will output the count of the number of students and the class average to the screen. Additionally, she wants to output the results of each row to the file for error checking. Check the example results from her class1_out.txt file: 1 B 2 A 3 A 4 C 5 A 6 D 7 B 8 A 9 F 10 B 11 F 12 B 13 B 14 F 15 A 16 D 17 D 18 C 19 D 20 F 21 D 22 A 23 A Number of students: 23 Class Average: 69.69 Anastasia does not use the + or – modifiers for grades, so you can just use the standard letter grade scale relating to the below table: MY SCRIPT import java.io.File; import java.io.FileNotFoundException; import java.io.PrintWriter; import java.util.Scanner; public class Lab5 { public static void main(String[] args)throws FileNotFoundException { Scanner in = new Scanner(System.in); System.out.printf("Enter a filename: "); String input = in.next(); Scanner sc = new Scanner(new File(input)); System.out.print("Enter an output file name: "); String output = in.next(); PrintWriter output2 = new PrintWriter(new File(output)); // methods of counting students and for toyal grades int lineCounter = 0; double total = 0; // Establingling While loop while (sc.hasNextLine()) { sc.next(); int grade = sc.nextInt(); total += grade; lineCounter++; if (grade >= 90) { output2.println("A"); } if (grade >= 80 && grade <= 89) { output2.println("B"); } if (grade >= 70 && grade <= 79) { output2.println("C"); } if (grade >= 60 && grade <= 69) { output2.println("D"); } if (grade <= 60) { output2.println("F"); } } // Estimate formula for average double avg = total / lineCounter; output2.printf("Class Average: %.2f", avg); System.out.println("Number of students; " + lineCounter); System.out.printf("Class Average: %.2f", avg); // closer scanner and printer output2.close(); sc.close(); } } I can't get full output: Enter a filename: class1.txt Enter an output file name: class1_out.txt Exception in thread "main" java.util.InputMismatchException at java.base/java.util.Scanner.throwFor(Scanner.java:947) at java.base/java.util.Scanner.next(Scanner.java:1602 really need some help.Thanks

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

Operations Management Sustainability And Supply Chain Management

Authors: Jay Heizer, Barry Render, Chuck Munson

13th Edition

0135173620, 978-0135173626

More Books

Students also viewed these Programming questions

Question

Calculate the , , R, and for the samples.

Answered: 1 week ago