Answered step by step
Verified Expert Solution
Question
1 Approved Answer
So far for my code I have: import java.io.*; import java.util.Scanner; public class extests { public static void main(String[] args) throws FileNotFoundException { String lastName;
So far for my code I have:
import java.io.*; import java.util.Scanner; public class extests { public static void main(String[] args) throws FileNotFoundException { String lastName; String firstName; int test1; int test2; int test3; Scanner input = new Scanner(new File("output.txt")); input.useDelimiter(":"); while (input.hasNextLine()) { lastName = input.next(); firstName = input.next(); test1 = Integer.parseInt(input.next()); test2 = Integer.parseInt(input.next()); test3 = Integer.parseInt(input.next()); //averaging student letter grade double overallGrade = (test1 * .25) + (test2 * .30) + (test3 * .45); String letterGrade; System.out.println(overallGrade); //counter for letter grade int counterA = 0; int counterB = 0; int counterC = 0; int counterD = 0; int counterF = 0; if (overallGrade >= 90) { letterGrade = "A"; counterA++; } else if (overallGrade >= 80) { letterGrade = "B"; counterB++; } else if (overallGrade >= 70) { letterGrade = "C"; counterC++; } else if (overallGrade >= 60) { letterGrade = "D"; counterD++; } else { letterGrade = "F"; counterF++; } try { BufferedWriter writer = new BufferedWriter(new FileWriter("/Users/joshuapermaul/Documents/Spring 2022/Data Structures/Problem2/output2.txt")); writer.write(lastName + ":" + firstName + ":" + test1 + ":" + test2 + ":" + test3 + ":" + overallGrade + ":" + letterGrade); writer.write(" A " + counterA + " B " + counterB + " C " + counterC + " D " + counterD + " F " + counterF); writer.close(); } catch (IOException e) { e.printStackTrace(); } System.out.println(lastName + " " + firstName + " " + letterGrade); } input.close(); } }
I'm stuck at getting the program to read multiple entries in the first text file. It stops at one and then presents an error. I'm guessing it's because the delimiter only works on ":" and then throws an error after when it runs into the next character. How would I fix it to where it will read all the entries.
2.35 Write a program that calculates the grades for a course. Your program should prompt the user for the name of a file that stores exam scores. Each line of the file has the following format: LastName:FirstName: Exam1: Exam2: Exam3 The exams are to be weighted 25% for the first exam, 30% for the second exam, and 45% for the third exam. Based on that, a final grade is to be assigned: A if the total is at least 90, B if it is at last 80, C if it is at least 70, D if it is at least 60, and F otherwise. The highest grade based on the total points is always assigned, so a 75 gets a C. Your program should output to the terminal a list of students with the let- ter grade, as follows: LastName FirstName LetterGrade It should also output to a file, whose name is provided by the user, lines of the form LastName FirstName Examl Exam2 Exam3 Total Points LetterGrade 68 chapter 2 reference types After it is done, it will output the grade distribution. If the input is Doe: John:100:100:100 Pantz: Smartee: 80:90:80 Then the terminal output is Doe John A Pantz Smartee B And the output file will contain Doe John 100 100 100 100 A Pantz Smartee 80 90 80 83 B A 1 B1 DO FOStep 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