EliPerfanova

Exam Preparation

Oct 11th, 2019
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.17 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class ExamPreparation {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         int badGrades = Integer.parseInt(scanner.nextLine());
  8.         String name = scanner.nextLine();
  9.  
  10.         int sum = 0;
  11.         int countBadGrades = 0;
  12.         int tasks = 0;
  13.         String last = "";
  14.  
  15.  
  16.         while (!name.equals("Enough")) {
  17.             int grade = Integer.parseInt(scanner.nextLine());
  18.             sum += grade;
  19.             tasks++;
  20.             if (grade <= 4) {
  21.                 countBadGrades++;
  22.             }
  23.             if (badGrades == countBadGrades) {
  24.                 System.out.printf("You need a break, %d poor grades.", countBadGrades);
  25.                 break;
  26.             }
  27.             last = name;
  28.             name = scanner.nextLine();
  29.  
  30.             if (name.equals("Enough")) {
  31.                 double average = sum * 1.0 / tasks;
  32.                 System.out.printf("Average score: %.2f%n", average);
  33.                 System.out.printf("Number of problems: %d%n", tasks);
  34.                 System.out.printf("Last problem: %s ", last);
  35.             }
  36.         }
  37.  
  38.  
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment