Advertisement
Guest User

Untitled

a guest
Oct 26th, 2020
645
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.33 KB | None | 0 0
  1. package Exams07072019;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class FootballTournament {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.         String name = scanner.nextLine();
  9.         int numberGames = Integer.parseInt(scanner.nextLine());
  10.  
  11.         int w = 0;
  12.         int d = 0;
  13.         int l = 0;
  14.         int points = 0;
  15.  
  16.         for (int i = 1; i <= numberGames; i++) {
  17.             String result = scanner.nextLine();
  18.  
  19.             if (result.equals("W")) {
  20.                 w++;
  21.                 points = points + 3;
  22.             } else if (result.equals("D")) {
  23.                 d++;
  24.                 points = points + 1;
  25.             } else if (result.equals("L")) {
  26.                 l++;
  27.             }
  28.         }
  29.         double percentWinGames = 1.0 * w / numberGames * 100;
  30.  
  31.         if (numberGames == 0) {
  32.             System.out.printf("%s hasn't played any games during this season.", name);
  33.         } else {
  34.             System.out.printf("%s has won %d points during this season.\n", name, points);
  35.             System.out.println("Total stats:");
  36.             System.out.printf("## W: %d\n", w);
  37.             System.out.printf("## D: %d\n", d);
  38.             System.out.printf("## L: %d\n", l);
  39.             System.out.printf("Win rate: %.2f%%",percentWinGames);
  40.         }
  41.  
  42.  
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement