// Tyler Rigsby, CSE 142 // Reads in an input file of section attendance grades and outputs the points and grades // for the students in each section. import java.util.*; import java.io.*; public class SectionAttendance { public static void main(String[] args) throws FileNotFoundException { Scanner input = new Scanner(new File("grades.txt")); // for each section (line): // save the line // process the line--get points from String // get the grades from the points int section = 1; while (input.hasNextLine()) { String line = input.nextLine(); int[] points = computePoints(line); double[] grades = computeGrades(points); reportResults(section, points, grades); section++; } } // Computes the points for each student in a line. public static int[] computePoints(String line) { int[] points = new int[5]; for (int i = 0; i < line.length(); i++) { // line = "hello" // line.charAt(2) --> 'l' char c = line.charAt(i); int value = 0; if (c == 'y') { value = 3; } else if (c == 'n') { value = 1; } points[i % 5] = Math.min(20, points[i % 5] + value); } return points; } // Compute the grades for each student based on their points as a percentage out of 20. public static double[] computeGrades(int[] points) { double[] grades = new double[points.length]; for (int i = 0; i < points.length; i++) { grades[i] = points[i] / 0.2; } return grades; } // Reports the results of a given section public static void reportResults(int section, int[] points, double[] grades) { System.out.println("Section " + section); System.out.println("Student points: " + Arrays.toString(points)); System.out.println("Student grades: " + Arrays.toString(grades)); System.out.println(); } }