Advertisement
Deiancom

Exam Preparation

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