SvetlanPetrova

ExamPreparation SoftUni

May 8th, 2021
958
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2.  
  3. public class ExamPreparation {
  4.     public static void main(String[] args) {
  5.  
  6.         Scanner scanner = new Scanner(System.in);
  7.  
  8.         int badLimit = Integer.parseInt(scanner.nextLine());
  9.         int badCount = 0;
  10.         int taskCount = 0;
  11.         double sumGrade = 0.0;
  12.         String lastTask = "";
  13.         boolean isFailed = true;
  14.  
  15.         while (badCount < badLimit) {
  16.             String task = scanner.nextLine();
  17.             if ("Enough".equals(task)) {
  18.                 isFailed = false;
  19.                 break;
  20.             }
  21.             int grade = Integer.parseInt(scanner.nextLine());
  22.             if (grade <= 4) {
  23.                 badCount ++;
  24.             }
  25.             sumGrade += grade;
  26.             taskCount ++;
  27.             lastTask = task;
  28.         }
  29.  
  30.         if (isFailed) {
  31.             System.out.printf("You need a break, %d poor grades.", badLimit);
  32.         }
  33.         else {
  34.             System.out.printf("Average score: %.2f%n", sumGrade / taskCount);
  35.             System.out.printf("Number of problems: %d%n", taskCount);
  36.             System.out.printf("Last problem: %s", lastTask);
  37.         }
  38.  
  39.     }
  40. }
  41.  
RAW Paste Data