/* This program reads a file representing which students attended which discussion sections and produces output of the students' section attendance and scores. Each line of the input file represents the data for one section and has the following format: 111111101011111101001110110110110001110010100 The data is for 5 students across 9 weeks, so you can think of each line as being split into 9 groups of 5: week1 week2 week3 week4 week5 week6 week7 week8 week9 11111 11010 11111 10100 11101 10110 11000 11100 10100 A 1 means a given student attended the section, and a 0 means the student did not. Within each group of 5, the first character is the first student's attendance, the second character is the second student's attendance, and so on. For example: week2 student1 student2 student3 student4 student5 1 1 0 1 0 The program produces the following output: Section #1: Sections attended: [9, 6, 7, 4, 3] Student scores: [20, 18, 20, 12, 9] Student grades: [100.0, 90.0, 100.0, 60.0, 45.0] Section #2: Sections attended: [6, 7, 5, 6, 4] Student scores: [18, 20, 15, 18, 12] Student grades: [90.0, 100.0, 75.0, 90.0, 60.0] Section #3: Sections attended: [5, 6, 5, 7, 6] Student scores: [15, 18, 15, 20, 18] Student grades: [75.0, 90.0, 75.0, 100.0, 90.0] */ import java.io.*; import java.util.*; public class Sections { public static void main(String[] args) throws FileNotFoundException { Scanner input = new Scanner(new File("sections.txt")); int section = 0; // used to count sections while (input.hasNextLine()) { // each line represents one section's data, such as // "111111101011111101001110110110110001110010100" String line = input.nextLine(); section++; System.out.println("Section #" + section + ":"); // count how many sections were attended int[] attended = new int[5]; for (int i = 0; i < line.length(); i++) { char c = line.charAt(i); // int studentNumber = i % 5; if (c == '1') { // the student attended that week's section attended[i % 5]++; } } System.out.println("Sections attended: " + Arrays.toString(attended)); // compute section score out of 20 points int[] scores = new int[5]; for (int i = 0; i < scores.length; i++) { scores[i] = Math.min(3 * attended[i], 20); } System.out.println("Student scores: " + Arrays.toString(scores)); // compute section grade out of 100% double[] grades = new double[5]; for (int i = 0; i < scores.length; i++) { grades[i] = 100.0 * scores[i] / 20; } System.out.println("Student grades: " + Arrays.toString(grades)); System.out.println(); } } }