Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package S5_WhileLoops;
- import java.util.Scanner;
- public class ExamPreparation {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int badGradesLimit = Integer.parseInt(scanner.nextLine());
- int sumGrades = 0;
- int gradesCounter = 0;
- String lastProblem = "";
- int badGradesCount = 0;
- boolean isBadGradesLimitReached = false;
- String command = scanner.nextLine();
- while (!command.equals("Enough")) {
- String taskName = command;
- int grade = Integer.parseInt(scanner.nextLine());
- // sumGrades = sumGrades + grade;
- sumGrades += grade;
- gradesCounter++;
- lastProblem = taskName;
- if (grade <= 4) {
- badGradesCount++;
- }
- if(badGradesCount == badGradesLimit) {
- break;
- }
- command = scanner.nextLine();
- }
- if(isBadGradesLimitReached) {
- System.out.printf("You need a break, %d poor grades.", badGradesCount);
- } else {
- System.out.printf("Average score: %.2f%n" +
- "Number of problems: %d%n" +
- "Last problem: %s", 1.0 * sumGrades/gradesCounter, gradesCounter, lastProblem);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement