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
Write a Java class called CityDistances in a class file called CityDistances.java.    2. Your methods...
Write a Java class called CityDistances in a class file called CityDistances.java.    2. Your methods will make use of two text files. a. The first text file contains the names of cities. However, the first line of the file is a number specifying how many city names are contained within the file. For example, 5 Dallas Houston Austin Nacogdoches El Paso b. The second text file contains the distances between the cities in the file described above. This file...
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...
Java... Write a class named TestScores. The class constructor should accept an array of test scores...
Java... Write a class named TestScores. The class constructor should accept an array of test scores as its argument. The class should have a method that returns the average of the test scores. If any test score in the array is negative or greater than 100, the class should throw an IllegalArgumentException. Demonstrate the class in a program (create a Driver class in the same file). The program should ask the user to input the number of test scores to...
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...
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...
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...
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)...
Play musical chords (JAVA PROGRAMMING) Notes and frequencies Every musical note has a name and a...
Play musical chords (JAVA PROGRAMMING) Notes and frequencies Every musical note has a name and a frequency. You are given a file where each line contains a note name, a tab character, and a frequence, which is a floating point value. For example, here are the first few lines from the file notes_frequencies.txt: A0 27.5 A#0 29.1353 B0 30.8677 C1 32.7032 C#1 34.6479 D1 36.7081 D#1 38.8909 E1 41.2035 F1 43.6536 Playing chords Write a program named PlayChords that first...