Question
Complete the following Java class. In this class, inside the main() method, user first enters the name of the students in a while loop. Then,
Complete the following Java class. In this class, inside the main() method, user first enters the name of the students in a while loop. Then, in an enhanced for loop, and by using the method getScores(), user enters the grades of each student. Finally, the list of the students and their final scores will be printed out using a for loop. Using the comments provided, complete the code in methods finalScore(), minimum(), and sum().
import java.util.Scanner;
import java.util.ArrayList;
public class GradeBook {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
ArrayList nameList = new ArrayList ();
ArrayList scoreList = new ArrayList ();
boolean done = false;
/* get student names */
while(!done) {
System.out.println("Enter a student name, Q to quit:");
String name = in.nextLine();
if (name.equals("Q")) done = true;
else nameList.add(name);
}
/* get grades for each student */
for (String n : nameList) {
scoreList.add(getScores(n, in));
}
/* print names of students and their final scores */
for (int i = 0; i < nameList.size(); i++) {
System.out.println(nameList.get(i) + ": " + scoreList.get(i));
}
}
/**
Gets the scores for an individual student, then
returns the final score for a list of scores.
@param name - the name of the student being processed
@return the sum of the scores, with the lowest score dropped if
there are at least two scores (by calling sum() and minimum()
methods), or 0 if there are no scores. If there is only one score,
it just returns that score.
*/
public static double getScores(String name, Scanner in) {
ArrayList scores = new ArrayList ();
System.out.println("Enter scores for " + name + ", Q to quit:");
while (in.hasNextDouble()) {
scores.add(in.nextDouble());
}
in.next(); // Read off "Q"
return finalScore(scores);
}
/**
Gets the final score for a list of scores.
@param scores - the list of scores for one student to process
@return the sum of the scores, with the lowest score dropped if
there are at least two scores (by calling sum() and minimum()
methods), or 0 if there are no scores. If there is only one score,
it just returns that score.
*/
public static double finalScore(ArrayList scores) {
*/ Complete this method using its comments:
}
/**
Gets the minimum score in a list of scores.
@param scores - the list of scores for one student to process
@return the minimum score, or 0 if there are no scores.
*/
public static double minimum(ArrayList scores) {
*/ Complete this method using its comments:
}
/**
Computes the sum of the scores in a list of scores.
@param scores - the list of scores for one student to process
@return the sum of the scores
*/
public static double sum(ArrayList scores) {
*/ Complete this method using its comments:
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started