/****************************************************************************** * Name: Kevin Wayne * NetID: wayne * Precept: P00 * * Description: This program reads grade data from standard input and * prints all students whose weighted average is greater than * (or equal to) a threshold value specifed as a command-line * argument. ******************************************************************************/ public class Grades { public static void main(String[] args) { // print only scores above this threshold double threshold = Double.parseDouble(args[0]); // number of assessments int NUMBER_OF_ASSESSMENTS = 6; // weights[i] = weight of assessment i double[] weights = new double[NUMBER_OF_ASSESSMENTS]; StdIn.readString(); for (int i = 0; i < NUMBER_OF_ASSESSMENTS; i++) { weights[i] = StdIn.readDouble(); } // maxScore[i] = max score for assessment i int[] maxScore = new int[NUMBER_OF_ASSESSMENTS]; StdIn.readString(); for (int i = 0; i < NUMBER_OF_ASSESSMENTS; i++) { maxScore[i] = StdIn.readInt(); } // compute grade of each student while (!StdIn.isEmpty()) { // student's name String name = StdIn.readString(); // compute weighted average, as you read in scores double weightedAverage = 0.0; for (int i = 0; i < NUMBER_OF_ASSESSMENTS; i++) { int score = StdIn.readInt(); weightedAverage += weights[i] * score / maxScore[i]; } // print if above specified threshold if (weightedAverage >= threshold) StdOut.printf("%7.3f %s\n", weightedAverage, name); } } }