// Helene Martin, CSE 142 // Calculates scores for section attendance based on a data file // This is an unstructured version import java.util.*; import java.io.*; public class SectionUnstructured { public static void main(String[] args) throws FileNotFoundException { Scanner fScan = new Scanner(new File("sections.txt")); int section = 1; while (fScan.hasNextLine()) { int[] scores = new int[5]; String line = fScan.nextLine(); for (int i = 0; i < line.length(); i++) { char c = line.charAt(i); if (c == 'y') { // every fifth score belongs to a particular student scores[i % 5] += 3; } else if (c == 'n') { scores[i % 5]++; } // cap scores at 20; scores[i % 5] = Math.min(scores[i % 5], 20); } double[] percents = new double[5]; for (int i = 0; i < scores.length; i++) { percents[i] = scores[i] / 20.0 * 100; } System.out.println("Section " + section); System.out.println("Student scores: " + Arrays.toString(scores)); System.out.println("Student percent: " + Arrays.toString(percents)); System.out.println(); section++; } } }