Question
Calculating the Grades for the Entire Class ! Modify the program of Home work 3 to read its input from a file called scores.dat (Both
Calculating the Grades for the Entire Class! Modify the program of Home work 3 to read its input from a file called scores.dat (Both of the HW3 and Scores.dat file are in the bottom of this question).
Ensure it works for one student first, then make it work for all of the students in the file. The data for each student in the file will adhere to the following format, where each element is separated by either a space or a tab character:
id number a1 a2 a3 a4 a5 a6 a7 L1 L2 L3 L4 L5 L6 L7 L8 L9 L10 midterm1 midterm2 final id number a1 a2 a3 a4 a5 a6 a7 L1 L2 L3 L4 L5 L6 L7 L8 L9 L10 midterm1 midterm2 final id number a1 a2 a3 a4 a5 a6 a7 L1 L2 L3 L4 L5 L6 L7 L8 L9 L10 midterm1 midterm2 final . . . It is important to notice that this file only contains the integer portion of the student ID numbers. The output, written to the screen, should be the last four digits of the student number, the final percentage, and the final letter grade. Additionally, there should be a summary of the number of students who received each grade (that is, the number of A+'s, A,'s, B+'s, B's, B-'s, C+'s, C's, D's and F's). Consider the sample file below, that contains only a single students information (the real requirements of the exercise are for both single student and the whole class, so the sample below is just for you to check in case of single student).
Here are some specific directions for this assignment: The program prompts the user to input the passing grade for the final exam from the keyboard. The program obtains all student (assignment, lab and exam) grades from an input file called scores.dat. There is no need to check to see if the grades are in the correct range: You can assume that what done when the input file was created. Marking Your mark will be based on: - Your code compiles and runs without errors - Your program runs and produces exactly the same output as the sample output, for the same input, calculating students grades and grade summaries correctly. IMPORTANT: You can only open 2 new Scanner objects: one to the keyboard input, one to the file input. More than 2 may produce output, but will not be considered correct. Observe that your program will be tested with an input file that contains different input (that still follows these specifications.) - Your code follows the coding convention precisely, in particular: + indentation using exactly 1 tab stop or 4 spaces within each layer of braces, + appropriate choice of identifiers + documentation comments, including header comment, class comment, and method description comments. + clear, consistent and concise implementation comments. - Your code uses parameterized methods and return values, where appropriate, to ensure there is little or no code redundancy.
Scores.dat:
804403 8.5 8.75 10 9.5 10 7 8.3 1 1 1 1 1 1 1 1 1 1 78 84 88 888888 10 10 10 10 10 10 10 1 1 1 1 1 1 1 1 1 1 80 100 100 818181 10 10 10 10 10 10 10 1 1 1 1 1 1 1 1 1 1 72.5 92 95 860003 6.5 6.75 10 10 9.5 4 7.6 1 1 1 1 1 1 1 1 1 1 50 84 88 000000 8 5 10 9.5 10 4 8 1 1 0 0 1 1 1 1 0 0 90 84 88 392384 7 7 7 7 7 7 7 0 0 1 1 1 1 0 1 0 1 68 80 83.7 808080 10 10 10 9.5 10 10 10 1 1 1 1 1 1 1 1 1 1 85 90 50 485939 5 5 5 5 5 5 5.5 1 0 1 1 1 1 0 1 1 1 77 70 70 485939 5 5 5 5 5 5 5.5 1 1 1 1 1 1 1 1 1 0 71 60 50 382901 10 10 10 10 10 10 10 1 1 1 1 1 1 1 1 1 1 51 45 55 860403 5 6.75 10 10 9.5 4 7.6 1 1 1 0 1 1 1 1 1 0 76 84 49.5
HW3 code has done:
import java.util.*; import java.io.File;
// Permission to use up to 2 methods in HW 4: /* * The class Grade contains methods for calculating the * weighted average of a number of assessments, the letter * grade given a percentage grade and an overall course * percentage grade. */
public class Grade { // Class contstants, eases changes to numbers of assessments and weightings public static final int NUM_ASSGTS = 7; public static final int NUM_LABS = 10; public static final int NUM_MTs = 2; public static final int NUM_Final = 1; public static final double WEIGHT_ASSGTS = 3.0; public static final double WEIGHT_LABS = 0.5; public static final double WEIGHT_MTs = 16.0; public static final double WEIGHT_Final = 42.0; public static void main(String[] args) { Scanner input = new Scanner(System.in);
System.out.println(" C O U R S E G R A D E C A L C U L A T O R"); System.out.println(" Purpose: Calculates the weighted grade for a student in a course"); System.out.println(" Inputs: Assignment, Lab and Exam grades");
gradeProcessing(input); }
// gradeProcessing: inputs data and calculates a grade, sums each grade public static void gradeProcessing(Scanner inFile) {
double passingGrade;
// Get individual marks and calculate weighted grade. System.out.print("Passing Grade for Final ==> "); passingGrade = inFile.nextDouble();
double grade = weightedAverage("Assignment ", NUM_LABS, NUM_ASSGTS, WEIGHT_ASSGTS, inFile) ; grade += weightedAverage("Lab ", 1, NUM_LABS, WEIGHT_LABS, inFile); grade += weightedAverage("Midterm ", 100, NUM_MTs, WEIGHT_MTs, inFile); double finalExam = weightedAverage("Final Exam ", 100, NUM_Final, WEIGHT_Final, inFile);
// Failed final exam? if (finalExam 49.5) { grade = 49; } else grade += finalExam; } else grade += finalExam;
//Output percent and letter grade System.out.println(" "); System.out.printf(" Grade: %2.2f %s", grade, calculateLetter(grade)); }
// weightedAverage - Calculates the average grade for a certain course activity public static double weightedAverage(String activity, int max, int number, double weight, Scanner input) { double sum = 0.0; double grade;
System.out.println(); System.out.println("Input " + activity + "(maximum " + max +"):");
for (int i = 0; i "); grade = input.nextDouble(); if (grade > max || grade max || grade
if (grade
return letter; }
}
The program should produce output similar to the following COURSE G R A DE CA LCUL ATO R Purpose: Calculates the weighted grade for students in a course Inputs: The Assignment, Lab and Exam grades for students in a course e for Final --> 47 Passing Grad FILE INPUT being received . 4403: Grade: 86.50 A Final 36.96 Grade Number Receiving Grade A+ A- B+ B- C+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