/* INPUT FILE, sections.txt : 111111101011111101001110110110110001110110100 111011111010100110101110101010101110101101010 EXPECTED OUTPUT FORMAT (numbers may differ): Scores: 20/20 18/20 18/20 15/20 12/20 Grades: 100 90 90 75 60 Scores: 18/20 9/20 15/20 12/20 20/20 Grades: 90 45 75 60 100 */ import java.io.*; public class SectionScores { public static final int STUDENTS = 5; public static final int WEEKS = 9; public static void main(String[] args) throws FileNotFoundException { Scanner input = new Scanner(new File("sections.txt")); while (input.hasNextLine()) { String line = input.nextLine(); char[] numbers = line.toCharArray(); // {'1', '1', '1', '1', '1', '0', '1', '0'...} int[] studentScores = new int[STUDENTS]; for (int i = 0; i < numbers.length; i++) { int studentNumber = i % 5; if (numbers[i] == '1') { studentScores[studentNumber] = Math.min(20, studentScores[studentNumber] + 3); } /* i = 0 --> student 0 i = 1 --> student 1 ... i = 5 --> student 0 i = 6 --> student 1 .. i = 10 --> student 0 */ } // Scores: 20/20 18/20 18/20 15/20 12/20 System.out.print("Scores: "); for (int i = 0; i < studentScores.length; i++) { System.out.print(studentScores[i] + "/20 "); } System.out.println(); // Grades: 100 90 90 75 60 } } }