Advertisement
CoineTre

02. Exam Preparation

Nov 12th, 2020
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.21 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.         int  lowGradesLimit= Integer.parseInt(scanner.nextLine());
  7.         int failedCount = 0;
  8.         int gradesCount = 0;
  9.         double ratioSum= 0;
  10.         String lastExam = "";
  11.         boolean tired = false;
  12.         while (failedCount<lowGradesLimit){
  13.             String examName = scanner.nextLine();
  14.             if ("Enough".equals(examName)){
  15.                 tired = true;
  16.                 break;
  17.             }
  18.             int examScore = Integer.parseInt(scanner.nextLine());
  19.             if(examScore <=4){
  20.                 failedCount++;
  21.             }
  22.             ratioSum+=examScore;
  23.             gradesCount++;
  24.             lastExam=examName;
  25.         }
  26.         double ratioSumTotal = ratioSum /gradesCount;
  27.         if(!tired){
  28.             System.out.printf("You need a break, %d poor grades.",lowGradesLimit);
  29.         }else{
  30.             System.out.printf("Average score: %.2f%n",ratioSumTotal);
  31.             System.out.printf("Number of problems: %d%n",gradesCount);
  32.             System.out.printf("Last problem: %s",lastExam);
  33.         }
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement