Hi I need help with java project, please follow the instruction. Here is the Sou
ID: 3914812 • Letter: H
Question
Hi I need help with java project, please follow the instruction.Here is the Source code link for (TestScoreReader): http://www.jade-cheng.com/hpu/2012-spring/csci-2912/text-processing-and-wrapper-classes-ii/TestScoreReader.java.
import java.io.*; import java.util.Scanner;
/** The TestScoreReader class reads test scores as tokens from a file and calculates the average of each line of scores. */
public class TestScoreReader { private Scanner inputFile; private String line;
/** The constructor opens a file to read the grades from. @param filename The file to open. */ public TestScoreReader(String filename) throws IOException { File file = new File(filename); inputFile = new Scanner(file); } /** The readNextLine method reads the next line from the file. @return true if the line was read, false otherwise. */
public boolean readNextLine() throws IOException { boolean lineRead; // Flag variable // Determine whether there is more to read. lineRead = inputFile.hasNext();
// If so, read the next line. if (lineRead) line = inputFile.nextLine(); return lineRead; }
/** The getAverage method calculates the average of the last set of test scores read from the file. @return The average. */ public double getAverage() { int total = 0; // Accumulator double average; // The average test score
// Tokenize the last line read from the file. String[] tokens = line.split(","); // Calculate the total of the test scores. for (String str : tokens) { total += Integer.parseInt(str); } // Calculate the average of the scores. // Use a cast to avoid integer division. average = (double) total / tokens.length; // Return the average. return average; } /** The close method closes the file. */ public void close() throws IOException { inputFile.close(); } } And (TestAverages) source code: http://www.jade-cheng.com/hpu/2012-spring/csci-2912/text-processing-and-wrapper-classes-ii/TestAverages.java?
import java.io.*; // Needed for IOException
/** This program uses the TestScoreReader class to read test scores from a file and get their averages. */
public class TestAverages { public static void main(String[] args) throws IOException { double average; // Test average int studentNumber = 1; // Control variable // Create a TestScoreReader object. TestScoreReader scoreReader = new TestScoreReader("Grades.csv"); // Display the averages. while (scoreReader.readNextLine()) { // Get the average from the TestScoreReader. average = scoreReader.getAverage(); // Display the student's average. System.out.println("Average for student " + studentNumber + " is " + average);
// Increment the student number. studentNumber++; } // Close the TestScoreReader. scoreReader.close(); System.out.println("No more scores."); } } Here is the Source code link for (TestScoreReader): http://www.jade-cheng.com/hpu/2012-spring/csci-2912/text-processing-and-wrapper-classes-ii/TestScoreReader.java.
import java.io.*; import java.util.Scanner;
/** The TestScoreReader class reads test scores as tokens from a file and calculates the average of each line of scores. */
public class TestScoreReader { private Scanner inputFile; private String line;
/** The constructor opens a file to read the grades from. @param filename The file to open. */ public TestScoreReader(String filename) throws IOException { File file = new File(filename); inputFile = new Scanner(file); } /** The readNextLine method reads the next line from the file. @return true if the line was read, false otherwise. */
public boolean readNextLine() throws IOException { boolean lineRead; // Flag variable // Determine whether there is more to read. lineRead = inputFile.hasNext();
// If so, read the next line. if (lineRead) line = inputFile.nextLine(); return lineRead; }
/** The getAverage method calculates the average of the last set of test scores read from the file. @return The average. */ public double getAverage() { int total = 0; // Accumulator double average; // The average test score
// Tokenize the last line read from the file. String[] tokens = line.split(","); // Calculate the total of the test scores. for (String str : tokens) { total += Integer.parseInt(str); } // Calculate the average of the scores. // Use a cast to avoid integer division. average = (double) total / tokens.length; // Return the average. return average; } /** The close method closes the file. */ public void close() throws IOException { inputFile.close(); } } And (TestAverages) source code: http://www.jade-cheng.com/hpu/2012-spring/csci-2912/text-processing-and-wrapper-classes-ii/TestAverages.java?
import java.io.*; // Needed for IOException
/** This program uses the TestScoreReader class to read test scores from a file and get their averages. */
public class TestAverages { public static void main(String[] args) throws IOException { double average; // Test average int studentNumber = 1; // Control variable // Create a TestScoreReader object. TestScoreReader scoreReader = new TestScoreReader("Grades.csv"); // Display the averages. while (scoreReader.readNextLine()) { // Get the average from the TestScoreReader. average = scoreReader.getAverage(); // Display the student's average. System.out.println("Average for student " + studentNumber + " is " + average);
// Increment the student number. studentNumber++; } // Close the TestScoreReader. scoreReader.close(); System.out.println("No more scores."); } }
Dr. Harrison keeps student scores in an Excel file. This can be exported as a comma separated text file. Each student's data will be on one line. We want to write a Java program that will find the average for each student. (The number of students changes each year.) Modify the source code included to do the TestAverages.java TestScoreReader java following: Instead of reading the data from the Excel spreadsheet, Create a database called Classes and a table called Grades with the fields and data as specified in the Excel attached 87 72 94 91 81 81 67 85 94 79 79 92 56 82 82 74 89 81 81 96 79 90 79
Explanation / Answer
import java.io.*; // Needed for IOException
/**
This program uses the TestScoreReader class
to read test scores from a file and get
their averages.
*/
public class TestAverages
{
public static void main(String[] args)
throws IOException
{
double average; // Test average
int studentNumber = 1; // Control variable
// Create a TestScoreReader object.
TestScoreReader scoreReader =
new TestScoreReader("src/Grades.csv");
// Display the averages.
while (scoreReader.readNextLine())
{
// Get the average from the TestScoreReader.
average = scoreReader.getAverage();
// Display the student's average.
System.out.println("Average for student " +
studentNumber + " is " +
average);
// Increment the student number.
studentNumber++;
}
// Close the TestScoreReader.
scoreReader.close();
System.out.println("No more scores.");
}
}
----------------------------------------------------------------------------------------------------------------
import java.io.*;
import java.util.Scanner;
/**
The TestScoreReader class reads test scores as
tokens from a file and calculates the average
of each line of scores.
*/
public class TestScoreReader
{
private Scanner inputFile;
private String line;
/**
The constructor opens a file to read
the grades from.
*/
public TestScoreReader(String filename)
throws IOException
{
File file = new File(filename);
inputFile = new Scanner(file);
}
/**
The readNextLine method reads the next line
from the file.
@return true if the line was read, false
otherwise.
*/
public boolean readNextLine() throws IOException
{
boolean lineRead; // Flag variable
// Determine whether there is more to read.
lineRead = inputFile.hasNext();
// If so, read the next line.
if (lineRead)
line = inputFile.nextLine();
return lineRead;
}
/**
The getAverage method calculates the average
of the last set of test scores read from the file.
*/
public double getAverage()
{
int total = 0; // Accumulator
double average; // The average test score
// Tokenize the last line read from the file.
String[] tokens = line.split(",");
// Calculate the total of the test scores.
for (String str : tokens)
{
total += Integer.parseInt(str);
}
// Calculate the average of the scores.
// Use a cast to avoid integer division.
average = (double) total / tokens.length;
// Return the average.
return average;
}
/**
The close method closes the file.
*/
public void close() throws IOException
{
inputFile.close();
}
}