Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Boiler Plate Code. [Copy this into your project]. package com.company; import java.io.File; import java.io.FileNotFoundException; import java.io.PrintWriter; import java.util.Scanner; /** * */ public class HW4 {

image text in transcribed

image text in transcribed

Boiler Plate Code. [Copy this into your project]. package com.company; import java.io.File; import java.io.FileNotFoundException; import java.io.PrintWriter; import java.util.Scanner; /** * */ public class HW4 { /** * * @param args * @throws FileNotFoundException */ public static void main(String[] args) throws FileNotFoundException { PrintWriter writer = new PrintWriter("output.txt"); String[] namesA = null; double[] gradesA = null; processSection(writer, "grade1.txt", namesA, gradesA); String[] namesB = null; double[] gradesB = null; processSection(writer, "grade2.txt", namesB, gradesB); String[] namesC = null; double[] gradesC = null; processSection(writer, "grade3.txt", namesC, gradesC); // String[] namesAll = null; // double[] gradesAll = null; // merge(namesA, namesB, namesC, gradesA, gradesB, gradesC, namesAll, gradesAll); // process(writer, "Overall", namesAll, gradesAll); writer.close(); } /** * * @param writer * @param inputFileName * @param names * @param grades * @throws FileNotFoundException */ public static void processSection(PrintWriter writer, String inputFileName, String[] names, double[] grades) throws FileNotFoundException { File f = new File(inputFileName); Scanner reader = new Scanner(f); String section = reader.nextLine(); int size = reader.nextInt(); names = new String[size]; grades = new double[size]; int index = 0; while (reader.hasNext()) { names[index] = reader.next(); grades[index] = reader.nextDouble(); index++; } process(writer, section, names, grades); } /** * * @param writer * @param section * @param names * @param grades * @throws FileNotFoundException */ public static void process(PrintWriter writer, String section, String[] names, double[] grades) throws FileNotFoundException{ int minIndex = findMinIndex(grades); int maxIndex = findMaxIndex(grades); double average = findAverage(grades); flush(writer, section, minIndex, maxIndex, average, names, grades); } /** * * @param grades * @return */ public static int findMinIndex(double[] grades) { int minIndex = 0; // TODO - YOU NEED TO IMPLEMENT THIS METHOD // TODO - GIVEN THE ARRAY, RETURN THE INDEX THAT HAS MINIMUM SCORE return minIndex; } /** * * @param grades * @return */ public static int findMaxIndex(double[] grades) { int maxIndex = 0; // TODO - YOU NEED TO IMPLEMENT THIS METHOD // TODO - GIVEN THE ARRAY, RETURN THE INDEX THAT HAS MAXIMUM SCORE return maxIndex; } /** * * @param grades * @return */ public static double findAverage(double[] grades) { double average = 0; // TODO - YOU NEED TO IMPLEMENT THIS METHOD // TODO - GIVEN THE ARRAY, RETURN THE AVERAGE SCORE return average; } /** * * @param writer * @param section * @param minIndex * @param maxIndex * @param average * @param names * @param grades * @throws FileNotFoundException */ public static void flush(PrintWriter writer, String section, int minIndex, int maxIndex, double average, String[] names, double[] grades) throws FileNotFoundException { writer.write("-------------------------------" + " "); writer.write(section + " "); writer.write("Minimum: " + names[minIndex] + " , " + String.valueOf(grades[minIndex]) + " "); writer.write("Maximum: " + names[maxIndex] + " , " + String.valueOf(grades[maxIndex]) + " "); writer.write("Average: " + String.valueOf(average) + " "); writer.write("-------------------------------" + " "); } /** * * @param namesA * @param namesB * @param namesC * @param gradesA * @param gradesB * @param gradesC * @param namesAll * @param gradesAll */ public static void merge(String[] namesA, String[] namesB, String[] namesC, double[] gradesA, double[] gradesB, double[] gradesC, String namesAll[], double[] gradesAll) { // TODO - YOU NEED TO IMPLEMENT THIS METHOD // TODO - GIVEN THE 3 NAMES ARRAY, AND THE 3 GRADES ARRAY, // TODO - MERGE THEM INTO 1 NAMES ARRAY, and 1 GRADES ARRAY. } }

Reading, Processing and Processing data using Arrays and Files As you know CSS has multiple sections. Let's say all sections had their midterm1 and the grades were handed back to the students. You are tasked with writing a program that will give some analytics to the CSS department on how the students fared across all the three sections Further, let's assume, grades per section were provided via an input file "data1.txt" as below Section 142A John 97.5 Jim 99 Kathy 34 Steve 86.5 Stacy 43 Faith 88 You can safely assume the following 1, 2. 3. 4. File data is 100% valid First line will tell the section name Second line will tell you the number of entries (the number of students) From third 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 Read this file Create two arrays 1. 2. a. First to store the Grades b. Find highest, lowest and average scores. Create a new file called "output.txt". In this file write the highest score, lowest score, average score Repeat this for all 3 sections Merge the grades for three sections Find and write the highest score, lowest score, average score across the three sections Second to store the Names 3. 4. 5. 6. 7. Reading, Processing and Processing data using Arrays and Files As you know CSS has multiple sections. Let's say all sections had their midterm1 and the grades were handed back to the students. You are tasked with writing a program that will give some analytics to the CSS department on how the students fared across all the three sections Further, let's assume, grades per section were provided via an input file "data1.txt" as below Section 142A John 97.5 Jim 99 Kathy 34 Steve 86.5 Stacy 43 Faith 88 You can safely assume the following 1, 2. 3. 4. File data is 100% valid First line will tell the section name Second line will tell you the number of entries (the number of students) From third 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 Read this file Create two arrays 1. 2. a. First to store the Grades b. Find highest, lowest and average scores. Create a new file called "output.txt". In this file write the highest score, lowest score, average score Repeat this for all 3 sections Merge the grades for three sections Find and write the highest score, lowest score, average score across the three sections Second to store the Names 3. 4. 5. 6. 7

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Marketing The New Profit Frontier

Authors: Ed Burnett

1st Edition

0964535629, 978-0964535626

More Books

Students also viewed these Databases questions

Question

define EFFECTIVE PARTICIPATION

Answered: 1 week ago