// CSE 142, Summer 2008 (Helene Martin) // Tallies section scores for different sections. // Reports attendance, scores and grades for each student. // For this first version, we focused on just one section. import java.util.*; import java.io.*; public class Sections1 { public static void main(String[] args) throws FileNotFoundException { Scanner input = new Scanner(new File("sectionScores.txt")); // Helpful visualization for figuring out %5 trick // index: 012345678901234567890123456789012345678901234 // sect1: 111111101011111101001110110110110001110010100 // array: 012340123401234012340123401234012340123401234 System.out.println("Section #1"); String section = input.nextLine(); // Sections attended: [9, 6, 7, 4, 3] int[] attendance = new int[5]; for(int i = 0; i < section.length(); i++) { if(section.charAt(i) == '1') { attendance[i % 5]++; } } System.out.println("Sections attended: " + Arrays.toString(attendance)); // Student scores: [20, 18, 20, 12, 9] int[] scores = new int[5]; for(int i = 0; i < attendance.length; i++) { scores[i] = Math.min(attendance[i] * 3, 20); } System.out.println("Student scores: " + Arrays.toString(scores)); //Student grades: [100.0, 90.0, 100.0, 60.0, 45.0] double[] grades = new double[5]; for(int i = 0; i < scores.length; i++) { grades[i] = scores[i] / 20.0 * 100; } System.out.println("Student grades: " + Arrays.toString(grades)); System.out.println(); } }