// Allison Obourn, CSE 142 // Reads in an input file of section attendance grades and outputs // 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 { // for each section // read data fom file // caculate section number // add up points // compute grades // print results // Data transformatons: // file line -> points -> grades -> results Scanner input = new Scanner(new File("sections.txt")); int section = 0; while(input.hasNextLine()) { String line = input.nextLine(); section++; int[] points = computePoints(line); double[] grades = computeGrades(points); results(section, points, grades); } } // 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[5]; for(int i = 0; i < points.length; i++) { grades[i] = 100.0 * points[i] / 20; } return grades; } // 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++) { char c = line.charAt(i); int earned = 0; if(c == 'y') { earned = 3; } else if (c == 'n') { earned = 1; } int student = i % 5; points[student] = Math.min(points[student] + earned, 20); } return points; } // Prints the results of a given section public static void results(int section, int[] points, double[] grades) { System.out.println("Section " + section); System.out.println("Points: " + Arrays.toString(points)); System.out.println("Grades: " + Arrays.toString(grades)); System.out.println(); } }