Advertisement
finderabc

ExamPreparation ( While-Loop - Exercise )

Feb 11th, 2019
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 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.  
  7. int badGrades = Integer.parseInt(scanner.nextLine());
  8. String problemName = "";
  9.  
  10. int numberOfProblems = 0;
  11. int poorGrades = 0;
  12. int allGrades = 0;
  13. String lastTask = "";
  14.  
  15.  
  16. while (poorGrades < badGrades) {
  17. lastTask = problemName;
  18. problemName = scanner.nextLine();
  19. if (problemName.equals("Enough")) {
  20. double averageScore = allGrades * 1.0 / numberOfProblems;
  21. System.out.printf("Average score: %.2f%n", averageScore);
  22. System.out.printf("Number of problems: %d%n", numberOfProblems);
  23. System.out.printf("Last problem: %s", lastTask);
  24. break;
  25. }
  26. int grade = Integer.parseInt(scanner.nextLine());
  27. numberOfProblems++;
  28. if (grade <= 4) {
  29. poorGrades++;
  30. allGrades += grade;
  31. } else {
  32. allGrades += grade;
  33. }
  34.  
  35. if (poorGrades >= badGrades) {
  36. System.out.printf("You need a break, %d poor grades.", poorGrades);
  37. }
  38. }
  39.  
  40.  
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement