Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I got 3 output correct but cannot figure how to fix to make output 4 correct. Please fix my code. Thanks you. / This method
I got 3 output correct but cannot figure how to fix to make output 4 correct. Please fix my code. Thanks you.
/ This method calculates and returns the final grade given an ArrayList of grade averages. (aparam gradeAverages the ArrayList of grade averages areturn the final grade */ public static double calculatefinalGrade (ArrayList Double gradeAverages) \{ final double CATEGORY WEIGHT =0.25; double finalGrade =0; for (double average : gradeAverages) \{ finalGrade += average * CATEGORY WEIGHT; 7 return finalGrade; \} / This is the main method that reads in the file name from the user, reads the file and calculates the final grade, and outputs the final grade. (aparam args not used */ public static void main (String [] args) \{ Scanner console = new Scanner(System.in); String fileName: ArrayList gradeAverages = new ArrayList ( ); double finalGrade; boolean validFile = false; while (!validFile) \{ try \{ System. out.print ("Please enter the file name: "); fileName = console.next (); gradeAverages = readAverages (fileName); finalGrade = calculateFinalGrade (gradeAverages): System.out.printf("Your final grade is: s.2f",finalGrade); validFile = true; \} catch (FileNotFoundException e) \{ System. out.println ("File not found."); j j console.close (); \} j 1:Test that averages.txt gives correct grade average 30/ Input Your output Please enter the file name: Your final grade is: 86.85 2:Test that averages 2 .txt gives correct grade average Input Your output Please enter the file name: Your final grade is: 91.70 3:Test that non-existent file gives "File not found" Exception 20/ Input \begin{tabular}{l|l} Your output & Please enter the file name: File not found. \\ Please enter the file name: Your final grade is: 91.70 \end{tabular} 4:Test that averages3.txt that contains "hello" throws "End of file expected" Exception Output differs. See highlights below. Input Your output Please enter the file name: Your final grade is: 0.00 Expected output the file name: Please enter the file name: Your final grade is: 64.73Step 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