Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Allow the user to enter up to 20 student names, and for each student 3 quiz scor

ID: 3789844 • Letter: A

Question

Allow the user to enter up to 20 student names, and for each student 3 quiz scores (in the range 0-100). Once input is done, display each student’s name, their three quiz scores, and their quiz score average, one student per line. The output table does not need to line up perfectly in columns. Use dialog boxes for all input and output. Use 5 arrays, one for the names, 3 for the scores, and one for the average. Write a method that takes three values and returns their average, and use this to calculate each student’s average.

Main Question: (Java Programming )

Modify above quiz score program to get the list of student names (one word) and scores from a file. Output will also be to a file, with the average at the end of each line. Name your input file “scores.txt” and your output file “averages.txt”. For this, you may just read the data from the input file and output to the output file. No arrays are need

Explanation / Answer

Sample scores.txt

John 74 65 87
Rolf 87 89 76
David 46 78 98
Don 98 97 93

Program

package score;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;

public class FileScore {
   public static void main(String[] args) {
       try(BufferedReader br = new BufferedReader(new FileReader("scores.txt"))) {
           String output="";
            String line = br.readLine();
            while (line != null) {
                String scores[]=line.split(" ");
                float average = Float.parseFloat(scores[1])
                       +Float.parseFloat(scores[2])
                       +Float.parseFloat(scores[3])/3;
                line+=" "+average;
                output+=line+" ";
                line = br.readLine();
            }
            System.out.println(output);
            FileWriter fileWriter = new FileWriter("averages.txt");
           BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);
           bufferedWriter.write(output);
           bufferedWriter.close();
       } catch (Exception e) {
           e.printStackTrace();
       }
   }
}

Sample averages.txt

John 74 65 87 168.0
Rolf 87 89 76 201.33333
David 46 78 98 156.66667
Don 98 97 93 226.0

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote