Roadstar3

ExamPreparation

Nov 25th, 2019
615
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.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         int failedGrade = Integer.parseInt(scanner.nextLine());
  8.  
  9.         int failedTimes = 0;
  10.         int solvedProblems = 0;
  11.         double allSum = 0;
  12.         String lastProblem = "";
  13.         boolean isFailed = true;
  14.  
  15.         while (failedTimes < failedGrade) {
  16.             String problemName = scanner.nextLine();
  17.             if ("Enough".equals(problemName)) {
  18.                 isFailed = false;
  19.                 break;
  20.             }
  21.             int grade = Integer.parseInt(scanner.nextLine());
  22.             if (grade <= 4) {
  23.                 failedTimes++;
  24.             }
  25.             allSum += grade;
  26.             solvedProblems++;
  27.             lastProblem = problemName;
  28.         }
  29.         if (isFailed) {
  30.             System.out.printf("You need a break, %d poor grades.", failedGrade);
  31.         } else {
  32.             System.out.printf("Average score: %.2f%n", allSum / solvedProblems);
  33.             System.out.printf("Number of problems: %d%n", solvedProblems);
  34.             System.out.printf("Last problem: %s", lastProblem);
  35.         }
  36.  
  37.     }
  38. }
RAW Paste Data