Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

JAVA - Please follow the instructions as closely as possible. The courseData.txt

ID: 3914503 • Letter: J

Question

JAVA - Please follow the instructions as closely as possible. The courseData.txt is all the way down

courseData.txt

0.30 0.30 0.40

161

3333 70 60 50

4444 50 50 50

5555 80 90 80

0

162

1212 90 85 92

6666 60 80 90

7777 90 90 90

8888 95 87 93

9999 75 77 73

0

263

2222 90 65 75

8989 60 40 60

9090 70 80 30

0

Explanation / Answer

import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.util.Scanner; public class ClassAverage{ //.. class constants go here public static void main(String[] args) throws IOException{ int courseNumber; // number of the course Scanner inputFile; //file containing data try { // to handle file not found exception inputFile = new Scanner(new File("courseData.txt")); } catch (FileNotFoundException e){ System.out.print("File Not Found"); return; } //... any stuff you need to do one time float programWeight, midtermWeight, finalExamWeight; // weights for program, midterm, final exam programWeight = inputFile.nextFloat(); midtermWeight = inputFile.nextFloat(); finalExamWeight = inputFile.nextFloat(); //Per class, print a table of ID numbers, grades, weighted average //per student, and a pass or fail program grade. // the class average is also printed. while (inputFile.hasNext()){ courseNumber = inputFile.nextInt(); System.out.println("Grade Data For Class "+ courseNumber); System.out.println("ID Programs Midterm Final Weighted Average Programs grade"); System.out.println("-- ------ ------ ----- ---------------- --------------"); float classaverage=0; // average for each class int numberofid = 0; // number of id in each class while (true) { int id, programmarks, midterm, finalmarks; // store marks of program , midterm, and final exam float idaverage; // weighted average of each id String pass; // pass or fail grade id = inputFile.nextInt(); if (id == 0) // to check if we have reached the end of data for current class break; programmarks = inputFile.nextInt(); midterm = inputFile.nextInt(); finalmarks = inputFile.nextInt(); idaverage = (programmarks * programWeight) + (midterm * midtermWeight) + (finalmarks * finalExamWeight); //weighted average for current id pass = programmarks >= 70 ? "Pass" : "Fail"; classaverage += idaverage; // adding weighted average to class average numberofid++; System.out.println(id+" "+programmarks+" "+midterm+" "+finalmarks+" "+idaverage+" "+pass); } System.out.println("Class Average: "+ classaverage / numberofid); System.out.println(); } } }