// Zorah Fung, CSE 142 // This program takes in a file of section attendance scores and reports grades // for each student in each section. // In the data file: // -'y' represents 5 points (student went to section and turned in HW) // -'n' represents 2 point (student went to section but didn't turn in HW) // -'a' represents 0 points (student was absent) // Each student can get up to 30 section points. // // Note: This program is not yet finished. Will be completed on Wednesday, August 6 import java.util.*; import java.io.*; public class Section { public static void main(String[] args) throws FileNotFoundException { Scanner fileScan = new Scanner(new File("sections.txt")); while (fileScan.hasNextLine()) { String line = fileScan.nextLine(); int[] studentPoints = calculateStudentPoints(line); System.out.println("Student points: " + Arrays.toString(studentPoints)); } } // Reads in a line representing attendance for a particular section and returns // an array representing the total number of points received by each student in the class // Note: We've pulled out this code into a method, because it performs a single // data transformation, converting a String of attendance for students to an array of counts public static int[] calculateStudentPoints(String line) { int[] studentPoints = new int[5]; for (int i = 0; i < line.length(); i++) { char attendance = line.charAt(i); int studentIndex = i % 5; if (attendance == 'y'){ studentPoints[studentIndex] += 5; } else if (attendance == 'n') { studentPoints[studentIndex] += 2; } /*else { studentPoints[studentIndex] += 0; }*/ studentPoints[studentIndex] = Math.min(30, studentPoints[studentIndex]); } return studentPoints; } }