Advertisement
veronikaaa86

02. Exam Preparation

Nov 28th, 2021
337
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 poorGrades = Integer.parseInt(scanner.nextLine());
  10.  
  11. int countPoorGrades = 0;
  12. double sumGrades = 0;
  13. int countProblems = 0;
  14. String lastProblem = "";
  15. String inputLine = scanner.nextLine();
  16. while (!inputLine.equals("Enough")) {
  17. int grade = Integer.parseInt(scanner.nextLine());
  18. if (grade <= 4) {
  19. countPoorGrades++;
  20. }
  21. if (countPoorGrades >= poorGrades) {
  22. break;
  23. }
  24.  
  25. sumGrades = sumGrades + grade;
  26. countProblems++;
  27.  
  28. lastProblem = inputLine;
  29.  
  30. inputLine = scanner.nextLine();
  31. }
  32.  
  33. double avgGrade = sumGrades / countProblems;
  34. if (inputLine.equals("Enough")) {
  35. System.out.printf("Average score: %.2f%n", avgGrade);
  36. System.out.printf("Number of problems: %d%n", countProblems);
  37. System.out.printf("Last problem: %s%n", lastProblem);
  38. } else {
  39. System.out.printf("You need a break, %d poor grades.%n", countPoorGrades);
  40. }
  41. }
  42. }
  43.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement