Question: Reading and Processing data using Class Arrays and Files This HW is a modification of HW4 with two main changes We will work with just





Reading and Processing data using Class Arrays and Files This HW is a modification of HW4 with two main changes We will work with just one file. i.e just one section We will use a StudentGrade class to encapsulate the Student Name and his/her Grade 1. 2. Thus, let's assume, grades were provided via an input file "data.txt" as below. (plz note this input file does not have section name.) John 97.5 Jim 99 Kathy 34 Steve 86.5 Stacy 43 Faith 88 You can safely assume the following 1, 2. 3. File data is 100% valid First line will tell you the number of entries (the number of students) From second line onwards, you will have a Name score pair a. b. C. d. e. There will be only 2 entries per line. Name and Score, and nothing else There will be exact 1 space between Name and Score Grades will always be a double type. Always between 0 and 100 Name will always be a String type Names, Scores, Min and Max is unique within and across sections Requirements 1. 2. 3. 4. 5. Read this file Create a StudentGrade arrays whose size is same as is specified in the file that is read Translate every line into a StudentGrade object and add it to the array Process this array to find the student with highest, lowest and average scores Create a new file called "output.txt". In this file write the highest score, lowest score, average score Approaclh 1. 2. Create new project Create a file inside this project. Call it StudentGrade.java 3. Replace the entire contents of the file with the code snippet below marked under StudentGrade.java Create a second file inside this project. Call it HW6.java 5. 4. Replace the entire contents of the file with the code snippet below marked under HW6.java 6. Copy the sample file "grade.txt" below (after the code snippet) into the root folder 7. Compile the code. Ensure the code compiles successfully 8. Implement initialize method 9. Implement findAverage, findMinimum and findMaximum methods. 10. Implement flush method 11. Implement any necessary constructor and getters/setters in the StudentGrades class 12. Feel good, and send a thank you note to those who helped you Rubrics and Notes: 1. 2. 3. If a program does not compile, you will get 0 If a program throws exception upon invoking, you will get 0 Below table is the points assignment Step1-7 Step8 Step9 Step10 Step11 Step12 Good comments Overall Clarity and Correctness(@Graders discretion) TOTAL 30 Boiler Plate Code. [Copy this into your project] StudentGrade.java package com.company; public class StudentGrade f private String name; private double grade; TODO - PLEASE ADD CONSTUCTOR AND GETTERS/SETTERS HW6.java package com.company import java.io.File; import java.io.FileNotFoundException; import java.io.Printwriter; import java.util.Scanner: ksk public class HW6 f public static void main(String[] args) throws FileNotFoundException f StudentGrade[] studentGradesA initialize("grade.txt"); process(studentGradesA); public static StudentGrade [] initialize(String inputFileName) throws FileNotFoundException TODO YOU NEED TO IMPLEMENT THIS METHOD / TODO -READ THE PASSED FILE /TODO -CREATE STUDENTGRADES ARRAY // TODO-FILL THS STUDENTGRADES ARRAY WITH STUDENT OBJECTS TODO RETURN THIS STUDENTGRADES ARRAY TO THE CALLER return null; public static void process (StudentGrade[] studentGrades) throws FileNotFoundException / Get the student with min grade StudentGrade studentGradeMin findMinIndex( studentGrades): // Get the student with max grade StudentGrade studentGradeMax -findMaxIndex (studentGrades); /I get the average grade double average = findAverage(studentGrades); flush these details to the fil flush(studentGradeMin, studentGradeMax, average, "output.txt"); public static StudentGrade findMinIndex(StudentGrade [] studentGrades) TODO-YOU NEED TO IMPLEMENT THIS METHOD TODO GIVEN THE ARRAY, RETURN THE STUDENT THAT HAS MINIMUM SCORE return null; public static StudentGrade findMaxIndex (StudentGrade l] studentGrades) // TODO-YOU NEED TO MPLEMENT THS METHOD TODO GIVEN THE ARRAY, RETURN THE STUDENT THAT HAS MAXIMUM SCORE return null; public static double findAverage(StudentGrade [] studentGrades) double average0; TODO YOU NEED TO IMPLEMENT THIS METHOD TODO - GIVEN THE ARRAY, RETURN THE AVERAGE SCORE return average; public static void flush (StudentGrade studentGradeMinimum, StudentGrade studentGradeMaximum, double average, String outputFileName) throws FileNotFoundException TODO: You will need to modify this method to also print TODO: the additional analytical data for overall section Printwriter writer -new PrintWriter(outputFileName); writer.write(" writer.write("Minimum: "+"WRITE THE MIN STUDENT DETAILS""n") writer.write("Maximum: "+"WRITE THE MAX STUDENT DETAILS" "In") writer.write( "Average: "+ String.valueOf(average) "In) writer.write(" writer.close(): Sample Input file. [Please test your code with your own input files] John 97.5 Jim 99 Kathy 34 Steve 86.5 Stacy 43 Faith 88 Reading and Processing data using Class Arrays and Files This HW is a modification of HW4 with two main changes We will work with just one file. i.e just one section We will use a StudentGrade class to encapsulate the Student Name and his/her Grade 1. 2. Thus, let's assume, grades were provided via an input file "data.txt" as below. (plz note this input file does not have section name.) John 97.5 Jim 99 Kathy 34 Steve 86.5 Stacy 43 Faith 88 You can safely assume the following 1, 2. 3. File data is 100% valid First line will tell you the number of entries (the number of students) From second line onwards, you will have a Name score pair a. b. C. d. e. There will be only 2 entries per line. Name and Score, and nothing else There will be exact 1 space between Name and Score Grades will always be a double type. Always between 0 and 100 Name will always be a String type Names, Scores, Min and Max is unique within and across sections Requirements 1. 2. 3. 4. 5. Read this file Create a StudentGrade arrays whose size is same as is specified in the file that is read Translate every line into a StudentGrade object and add it to the array Process this array to find the student with highest, lowest and average scores Create a new file called "output.txt". In this file write the highest score, lowest score, average score Approaclh 1. 2. Create new project Create a file inside this project. Call it StudentGrade.java 3. Replace the entire contents of the file with the code snippet below marked under StudentGrade.java Create a second file inside this project. Call it HW6.java 5. 4. Replace the entire contents of the file with the code snippet below marked under HW6.java 6. Copy the sample file "grade.txt" below (after the code snippet) into the root folder 7. Compile the code. Ensure the code compiles successfully 8. Implement initialize method 9. Implement findAverage, findMinimum and findMaximum methods. 10. Implement flush method 11. Implement any necessary constructor and getters/setters in the StudentGrades class 12. Feel good, and send a thank you note to those who helped you Rubrics and Notes: 1. 2. 3. If a program does not compile, you will get 0 If a program throws exception upon invoking, you will get 0 Below table is the points assignment Step1-7 Step8 Step9 Step10 Step11 Step12 Good comments Overall Clarity and Correctness(@Graders discretion) TOTAL 30 Boiler Plate Code. [Copy this into your project] StudentGrade.java package com.company; public class StudentGrade f private String name; private double grade; TODO - PLEASE ADD CONSTUCTOR AND GETTERS/SETTERS HW6.java package com.company import java.io.File; import java.io.FileNotFoundException; import java.io.Printwriter; import java.util.Scanner: ksk public class HW6 f public static void main(String[] args) throws FileNotFoundException f StudentGrade[] studentGradesA initialize("grade.txt"); process(studentGradesA); public static StudentGrade [] initialize(String inputFileName) throws FileNotFoundException TODO YOU NEED TO IMPLEMENT THIS METHOD / TODO -READ THE PASSED FILE /TODO -CREATE STUDENTGRADES ARRAY // TODO-FILL THS STUDENTGRADES ARRAY WITH STUDENT OBJECTS TODO RETURN THIS STUDENTGRADES ARRAY TO THE CALLER return null; public static void process (StudentGrade[] studentGrades) throws FileNotFoundException / Get the student with min grade StudentGrade studentGradeMin findMinIndex( studentGrades): // Get the student with max grade StudentGrade studentGradeMax -findMaxIndex (studentGrades); /I get the average grade double average = findAverage(studentGrades); flush these details to the fil flush(studentGradeMin, studentGradeMax, average, "output.txt"); public static StudentGrade findMinIndex(StudentGrade [] studentGrades) TODO-YOU NEED TO IMPLEMENT THIS METHOD TODO GIVEN THE ARRAY, RETURN THE STUDENT THAT HAS MINIMUM SCORE return null; public static StudentGrade findMaxIndex (StudentGrade l] studentGrades) // TODO-YOU NEED TO MPLEMENT THS METHOD TODO GIVEN THE ARRAY, RETURN THE STUDENT THAT HAS MAXIMUM SCORE return null; public static double findAverage(StudentGrade [] studentGrades) double average0; TODO YOU NEED TO IMPLEMENT THIS METHOD TODO - GIVEN THE ARRAY, RETURN THE AVERAGE SCORE return average; public static void flush (StudentGrade studentGradeMinimum, StudentGrade studentGradeMaximum, double average, String outputFileName) throws FileNotFoundException TODO: You will need to modify this method to also print TODO: the additional analytical data for overall section Printwriter writer -new PrintWriter(outputFileName); writer.write(" writer.write("Minimum: "+"WRITE THE MIN STUDENT DETAILS""n") writer.write("Maximum: "+"WRITE THE MAX STUDENT DETAILS" "In") writer.write( "Average: "+ String.valueOf(average) "In) writer.write(" writer.close(): Sample Input file. [Please test your code with your own input files] John 97.5 Jim 99 Kathy 34 Steve 86.5 Stacy 43 Faith 88
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
