// Reads an input file containing attendance information and reporting for each // student their attendance for each day of the week and calculating which day's // lectures were attended most frequently. /* DEVELOPMENT NOTES: ((Note: this is not something you should include in your own programs; this is included here to aid in your understanding and to provide additional context for the program.)) This is the version that we started together in class. We focused on decomposing the problem, the would later refactor the program with methods in the final version of this program. See AttendanceFinal.java */ import java.util.*; import java.io.*; public class AttendanceFirstAttempt { public static void main(String[] args) throws FileNotFoundException { Scanner input = new Scanner(new File("attendance.txt")); // line based processing int studentCount = 1; while (input.hasNextLine()) { String attendanceLine = input.nextLine(); // count the weekdays a student attended lecture int[] weekdayCounts = new int[5]; for (int i = 0; i < attendanceLine.length(); i++) { // do something with attendanceLine.charAt(i) char nextLetter = attendanceLine.charAt(i); if (nextLetter == 'y') { weekdayCounts[i % 5]++; } } // find the max weekday int maxIndex = 0; for (int i = 0; i < weekdayCounts.length; i++) { if (weekdayCounts[maxIndex] < weekdayCounts[i]) { maxIndex = i; } } // "lookup array" String[] weekdays = {"Mon", "Tues", "Wed", "Thurs", "Fri"}; studentCount++; // print results System.out.println("Student #" + studentCount + "'s attendance data"); System.out.println(" M T W Th F"); System.out.println(" " + Arrays.toString(weekdayCounts)); System.out.println(" Attended " + weekdays[maxIndex] + " lectures most often"); System.out.println(); } } }