galinyotsev123

ProgBasics05while-Loop-Y03examPreparation

Jan 7th, 2019
66
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 Y03examPreparation {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6.  
  7. int maxPoorGrades = Integer.parseInt(scanner.nextLine());
  8. int counterPoorGrades = 0;
  9. int counterAlltask = 0;
  10.  
  11. double averageScore = 0;
  12.  
  13. int scoreAllGrades = 0;
  14. String lastProblem = "";
  15.  
  16. while (maxPoorGrades > counterPoorGrades){
  17. String task = scanner.nextLine();
  18. if (task.equals("Enough")){
  19. break;
  20. }
  21. int currentGrade = Integer.parseInt(scanner.nextLine());
  22. if (currentGrade <= 4){
  23. counterPoorGrades++;
  24. }
  25. counterAlltask++;
  26. scoreAllGrades += currentGrade;
  27. lastProblem = task;
  28. }
  29. averageScore = (scoreAllGrades * 1.0) / counterAlltask;
  30.  
  31. if (counterPoorGrades == maxPoorGrades){
  32. System.out.printf("You need a break, %d poor grades.",counterPoorGrades);
  33. }
  34. else {
  35. System.out.printf("Average score: %.2f%n", averageScore);
  36. System.out.printf("Number of problems: %d%n", counterAlltask);
  37. System.out.printf("Last problem: %s", lastProblem);
  38.  
  39. }
  40.  
  41.  
  42.  
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment