Advertisement
veronikaaa86

02. Exam Preparation

Feb 6th, 2022
503
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. package whileLoop;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class P02ExamPreparation {
  6. public static void main(String[] args) {
  7. Scanner scanner = new Scanner(System.in);
  8.  
  9. int maxPoorGrade = Integer.parseInt(scanner.nextLine());
  10.  
  11. int countProblems = 0;
  12. double sumGrade = 0;
  13. String lastProblem = "";
  14. int countPoorGrades = 0;
  15. String command = scanner.nextLine();
  16. while (!command.equals("Enough")) {
  17. String problemName = command;
  18. int grade = Integer.parseInt(scanner.nextLine());
  19.  
  20. if (grade <= 4) {
  21. countPoorGrades++;
  22. }
  23. if (countPoorGrades >= maxPoorGrade) {
  24. break;
  25. }
  26.  
  27. countProblems++;
  28. sumGrade = sumGrade + grade;
  29. lastProblem = problemName;
  30.  
  31. command = scanner.nextLine();
  32. }
  33.  
  34. if (countPoorGrades >= maxPoorGrade) {
  35. System.out.printf("You need a break, %d poor grades.", countPoorGrades);
  36. } else {
  37. System.out.printf("Average score: %.2f%n", sumGrade / countProblems);
  38. System.out.printf("Number of problems: %d%n", countProblems);
  39. System.out.printf("Last problem: %s%n", lastProblem);
  40. }
  41. }
  42. }
  43.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement