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 badGradesCount = 0;
- String lastProblem = "";
- int tasksCount = 0;
- int gradesSum = 0;
- // read command
- String command = scanner.nextLine();
- while (!command.equals("Enough")) {
- String taskName = command;
- int grade = Integer.parseInt(scanner.nextLine());
- // increment for printing
- gradesSum = gradesSum + grade;
- tasksCount++;
- lastProblem = taskName;
- // check for bad grades
- if(grade <= 4) {
- badGradesCount++;
- }
- // check if we have enough bad grades to stop
- if(badGradesCount == badGradesLimit) {
- break;
- }
- // read command once again
- command = scanner.nextLine();
- }
- // check if we got too many bad grades
- if(badGradesCount == badGradesLimit) {
- System.out.printf("You need a break, %d poor grades.",badGradesCount);
- } else {
- System.out.printf("Average score: %.2f%n", 1.0*gradesSum/tasksCount);
- System.out.printf("Number of problems: %d%n", tasksCount);
- System.out.printf("Last problem: %s", lastProblem);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement