Advertisement
willieshi232

Untitled

Dec 10th, 2015
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.*;
  3.  
  4. public class Sections {
  5. public static void main(String[] args) throws FileNotFoundException {
  6. Scanner input = new Scanner(new File("sections.txt"));
  7. int section = 1;
  8. while (input.hasNextLine()) {
  9. String line = input.nextLine(); // process one section
  10. int[] points = new int[5];
  11. for (int i = 0; i < line.length(); i++) {
  12. int student = i % 5;
  13. int earned = 0;
  14. if (line.charAt(i) == 'y') { // c == 'y' or 'n' or 'a'
  15. earned = 3;
  16. } else if (line.charAt(i) == 'n') {
  17. earned = 2;
  18. }
  19. points[student] = Math.min(20, points[student] + earned);
  20. }
  21.  
  22. double[] grades = new double[5];
  23. for (int i = 0; i < points.length; i++) {
  24. grades[i] = 100.0 * points[i] / 20.0;
  25. }
  26.  
  27. System.out.println("Section " + section);
  28. System.out.println("Student points: " + Arrays.toString(points));
  29. System.out.println("Student grades: " + Arrays.toString(grades));
  30. System.out.println();
  31. section++;
  32. }
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement