Question: Consider the code snippet below. You have to write a program that records the names and scores of students into a file and reads from

Consider the code snippet below. You have to write a program that records the names and scores of students into a file and reads from the same file to display the names and scores. The file is named student_scores.txt.[3+3+4=10 Marks] For example: If the data entered is: John: 95 Alice: 88 Bob: 72 Then the output should be: Writing to file successful.Writing to file successful.Writing to file successful.Reading from file:John: 95Alice: 88Bob: 72 To assist with the task, two methods writeToFile() and readFromFile() are given in the program.You have to fill the missing code in each of the methods, so that we get the above output. Java code:import java.io.*; public class StudentScores {// File name constant private static final String FILE_NAME = "student_scores.txt"; // Writes a student's name and score to the file public static void writeToFile(String name, int score){ try (BufferedWriter bw = new BufferedWriter(new FileWriter(FILE_NAME, true))){/*___MISSING CODE (A)___*/ System.out.println("Writing to file successful."); } catch (IOException e){ e.printStackTrace(); }}// Reads and displays the content of the file public static void readFromFile(){ System.out.println("Reading from file:"); try (BufferedReader br = new BufferedReader(new FileReader(FILE_NAME))){/*___MISSING CODE (B)___*/} catch (IOException e){ e.printStackTrace(); }}// The main method for testing the file read and write operations public static void main(String[] args){ writeToFile("John",95); writeToFile("Alice",88); writeToFile("Bob",72); /*___MISSING CODE (C)___*/}}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!