Question: Task For this lab you will fix the Quiz.java program. It tries to read in a list of quiz scores, drop the lowest score, and
Task
For this lab you will fix theQuiz.javaprogram. It tries to read in a list of quiz scores, drop the lowest score, and then return the average of the remaining grades.
It uses a file calledscores.txtwhich you can download and test with. The test file doesnt have any problems and you can assume it will be there when the program runs.
The program itself, however, has a couple of compiler errors, as well as some run-time logic errors in it. Some of these run-time problems will be exceptions that crash the program and one is a logic error that results in the wrong output. Your job is to fix these problems and get the code working.
When you are done, the example file should give the following output: --------------------- $ java Quiz Average is 4.5 --------------------- Contents of Quiz.java:
import java.io.FileInputStream;import java.io.FileNotFoundException;import java.util.ArrayList;import java.util.Scanner;import java.util.Collections;class QuizList { private ArrayList numbers; public void QuizList(String fileName) { // open the file Scanner input = null; try { FileInputStream file = new FileInputStream(fileName); input = new Scanner(file); } catch (FileNotFoundException e) { System.out.println("Error, file could not be found!"); System.exit(-1); } // read the data while (input.hasNext()) { numbers.add(input.nextInt()); } } // drop the lowest grade out of the list public void dropLowest() { // sort the data in ascending order Collections.sort(numbers); // then drop the first element out numbers.remove(1); } // return the average of the numbers back public double average() { int sum = 0; for (int i = 0; i => sum += numbers.get(i) } return (double) sum / (double) numbers.size(); }}public class Quiz { public static void main(String args[]) { QuizList quizzes = new QuizList("scores.txt"); quizzes.dropLowest(); System.out.println("Average is " + quizzes.average); }}Contents of Scores.txt:540453555Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
