Advertisement
raliportokali

Untitled

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