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

Need a Java program named: P_Suplemental_9.java that reads from two text files.

ID: 3653952 • Letter: N

Question

Need a Java program named: P_Suplemental_9.java that reads from two text files. For this project the files would be located in file folder C:/temp (the context of both text files are listed below). File studentNames.txt contains a list of student id numbers and names. File studentScores.txt contains a list of student id numbers and scores. Read in both text files, then match the scores to the correct student based upon the id. System.out print each student's name and their average score. This is an introduction to Java class so no GUI is needed. All is from the command line. Contents of studentNames.txt 3305 Smith Henry 5555 Eddy Olivia 8915 Johnson Luke Contents of studentScores.txt 3305 92.0 5555 95.5 8915 98.5 3305 89.0 5555 90.5 8915 95.5 3305 78.5 5555 85.0 8915 82.0

Explanation / Answer

NOTE: TO USE THIS PROGRAM THE FILES studentNames.txt and studentScores.txt should be located in C: emp folder and you should have permissions to access that folder. If it doesn't work, change the file path in the program below. FILE FORMAT: For studentNames.txt, the studentID is followed by space and Student Name and then in the next line another student ID and so on. For studentScores.txt, the studentId is follwed by a space and studentscores and space and another studentID and so on. public class Student { private String studentName; private int studentID; private double totalscore = 0.0; private int NumberOfScores = 0; public Student(int ID,String name) { studentName = name; studentID = ID; } public String getStudentName() { return studentName; } public int getStudentID() { return studentID; } public double getTotalscore() { return totalscore; } public void addScore(double score) { totalscore += score; NumberOfScores++; } public double average() { if(NumberOfScores!= 0) return totalscore/NumberOfScores; else return 0; } public String toString() { return String.format("Name: %s. Student ID: %d ", studentName, studentID); } } import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class P_Suplemental_9 { private Scanner inputName; private Scanner inputScore; public void openFile() { try { inputName = new Scanner(new File("C:\temp\studentNames.txt")); } catch (FileNotFoundException e) { System.err.println("File "C:\temp\studentNames.txt" not found"); System.exit(1); } } public void openScoreFile() { try { inputScore = new Scanner(new File("studentScores.txt")); } catch (FileNotFoundException e) { System.err.println("File "studentScores.txt"not found"); System.exit(1); } } public void closeScoreFile() { inputScore.close(); } public void readFiles() { Student student; while(inputName.hasNext()) { openScoreFile(); String studentID = inputName.next(); String name = inputName.nextLine(); student = new Student(Integer.parseInt(studentID), name); while(inputScore.hasNext()) { if(Integer.parseInt(inputScore.next()) == student.getStudentID()) { student.addScore(Double.parseDouble(inputScore.next())); } else { String temp = inputScore.next(); } } closeScoreFile(); System.out.printf("%sAverage Score : %.2f ",student, student.average()); } inputName.close(); } } public class DriverProgram { public static void main(String[] args) { P_Suplemental_9 application = new P_Suplemental_9(); application.openFile(); application.readFiles(); } }

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