Question

Write a Java class called Grades in a class file called Grades.java. 2. Grades reads from...

Write a Java class called Grades in a class file called Grades.java.

2. Grades reads from a text file containing a series of course grades (a value between 0.0 and 100.0) with one grade entry per line. However, the first line in the file is an integer value specifying how many grade entries are contained in the file.

3. The Grades class contains four static methods: a. A method called loadGrades() that opens the file, reads in the data and returns an array of double containing grade values. The method takes a single argument called filename of type String that is the name of the file to be opened. If done correctly, the returned array should be the correct size to store all temperature values without any “extra” space within the array. If the file does not exist, then a FileNotFoundException is thrown.

Homework Answers

Answer #1

CODE

import java.io.BufferedReader;

import java.io.FileNotFoundException;

import java.io.FileReader;

import java.io.IOException;

public class Grades {

public static double[] loadGrades(String fileName) throws FileNotFoundException {

double[] grades;

try (FileReader reader = new FileReader(fileName);

BufferedReader br = new BufferedReader(reader)) {

int n = Integer.parseInt(br.readLine());

grades = new double[n];

String line;

int i=0;

while ((line = br.readLine()) != null) {

grades[i ++] = Double.parseDouble(line);

}

} catch (IOException e) {

System.err.format("IOException: %s%n", e);

throw new FileNotFoundException();

}

return grades;

}

}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Java programming. Write a public Java class called WriteToFile that opens a file called words.dat which...
Java programming. Write a public Java class called WriteToFile that opens a file called words.dat which is empty. Your program should read a String array called words and write each word onto a new line in the file. Your method should include an appropriate throws clause and should be defined within a class called TextFileEditor. The string should contain the following words: {“the”, “quick”, “brown”, “fox”}
Write C++ code to: Create a function called “ReadFile” that: Accepts a filename as input Opens...
Write C++ code to: Create a function called “ReadFile” that: Accepts a filename as input Opens the file for reading Reads an integer from the file and returns it. Create a main function that Asks the user to input a file Passes that file to the “ReadFile” function Prints the returned integer to the screen Extra Credit: Set a default argument of “intfile.txt” for the “ReadFile” function Write an overloaded function of “ReadFile” that accepts two filenames and reads an...
Write a program that reads a file named input.txt and writes a file that contains the...
Write a program that reads a file named input.txt and writes a file that contains the same contents, but is named output.txt. The input file will contain more than one line when I test this. Do not use a path name when opening these files. This means the files should be located in the top level folder of the project. Do not use a copy method that is supplied by Java. Your program must read the file line by line...
Download the ProductUpTo3.java file, and open it in jGrasp (or a text editor of your choice)....
Download the ProductUpTo3.java file, and open it in jGrasp (or a text editor of your choice). This program will read in three integers with Scanner, put the values in an array of int, and then print the product of the three values. Example output of the program is shown below, with user input shown in bold: Enter first integer: 3 Enter second integer: 4 Enter third integer: 5 Product: 60 More details about the method you need to write are...
Write a Java program that Reads baseball data in from a comma delimited file. Each line...
Write a Java program that Reads baseball data in from a comma delimited file. Each line of the file contains a name followed by a list of symbols indicating the result of each at bat: 1 for single, 2 for double, 3 for triple, 4 for home run, o for out, w for walk, s for sacrifice Statistics are computed and printed for each player. EXTRA CREDIT (+10 points); compute each player's slugging percentage https://www.wikihow.com/Calculate-Slugging-Percentage Be sure to avoid a...
I need this before the end of the day please :) In Java 10.13 Lab 10...
I need this before the end of the day please :) In Java 10.13 Lab 10 Lab 10 This program reads times of runners in a race from a file and puts them into an array. It then displays how many people ran the race, it lists all of the times, and if finds the average time and the fastest time. In BlueJ create a project called Lab10 Create a class called Main Delete what is in the class you...
THIS IS FOR JAVA I have to write a method for a game of Hangman. The...
THIS IS FOR JAVA I have to write a method for a game of Hangman. The word the user is trying to guess is made up of hashtags like so " ###### " If the user guesses a letter correctly then that letter is revealed on the hashtags like so "##e##e##" If the user guesses incorrectly then it increments an int variable named count " ++count; " String guessWord(String guess,String word, String pound) In this method, you compare the character(letter)...
please write the code in java so it can run on jGRASP import java.util.Scanner; 2 import...
please write the code in java so it can run on jGRASP import java.util.Scanner; 2 import java.io.*; //This imports input and output (io) classes that we use 3 //to read and write to files. The * is the wildcard that will 4 //make all of the io classes available if I need them 5 //It saves me from having to import each io class separately. 6 /** 7 This program reads numbers from a file, calculates the 8 mean (average)...
Use Java: Also: Please include screenshots if possible. Create a class called AbstractStackTest. Write an abstract...
Use Java: Also: Please include screenshots if possible. Create a class called AbstractStackTest. Write an abstract method called makeStack that returns a Stack of Strings. Use the Stack interface as the return type, not a specific implementation! Write a class named NodeStackTest that extends your AbstractStackTest class. Implement the makeStack method to return a NodeStack. Repeat parts 1 and 2 for the Queue interface and the NodeQueue implementation. Write a new stack implementation, ArrayStack. It should be generic and use...
In java //Create a New Project called LastNameTicTacToe.// //Write a class (and a client class to...
In java //Create a New Project called LastNameTicTacToe.// //Write a class (and a client class to test it) that encapsulates a tic-tac-toe board. // A tic-tac-toe board looks like a table of three rows and three columns partially or completely filled with the characters X and O. // At any point, a cell of that table could be empty or could contain an X or an O. You should have one instance variable, a two-dimensional array of values representing the...