Advertisement
GabrielHr00

TennisRanklist

Nov 20th, 2022
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. package S4_ForLoops;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class TennisRanklist {
  6. public static void main(String[] args) {
  7. Scanner scanner = new Scanner(System.in);
  8. int tournamentsCount = Integer.parseInt(scanner.nextLine());
  9. int startingPoints = Integer.parseInt(scanner.nextLine());
  10.  
  11. int tournamentsPoints = 0;
  12. int winsCount = 0;
  13.  
  14. for (int i = 1; i <= tournamentsCount; i++) {
  15. // read match result
  16. String result = scanner.nextLine();
  17.  
  18. // add points according to match result
  19. switch(result) {
  20. case "W":
  21. // winsCount += 1;
  22. winsCount++;
  23. tournamentsPoints += 2000;
  24. break;
  25. case "F":
  26. tournamentsPoints += 1200;
  27. break;
  28. case "SF":
  29. tournamentsPoints += 720;
  30. break;
  31. }
  32. }
  33.  
  34. // find needed variables
  35. int allPointsAfterTournaments = startingPoints + tournamentsPoints;
  36. int averagePointsFromTournaments = tournamentsPoints / tournamentsCount;
  37. double percentWonTournaments = 1.0*winsCount / tournamentsCount * 100;
  38.  
  39. // print results
  40. System.out.printf("Final points: %d%n", allPointsAfterTournaments);
  41. System.out.printf("Average points: %d%n", averagePointsFromTournaments);
  42. System.out.printf("%.2f%%", percentWonTournaments);
  43. }
  44. }
  45.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement