Advertisement
Valantina

FootballTournament/Ex/Java

Jul 9th, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.40 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class P05_FootballTournament {
  4.     public static void main(String[] args) {
  5.         Scanner scan = new Scanner(System.in);
  6.  
  7.         String teamName = scan.nextLine();
  8.         int gamesCount = Integer.parseInt(scan.nextLine());
  9.  
  10.         int totalPoints = 0;
  11.  
  12.         int totalWins = 0;
  13.         int totalDraws = 0;
  14.  
  15.         for (int i = 0; i < gamesCount; i++) {
  16.             String gameType = scan.nextLine();
  17.  
  18.             if ("W".equals(gameType)) {
  19.                 totalPoints += 3;
  20.                 totalWins++;
  21.             } else if ("D".equals(gameType)) {
  22.                 totalPoints += 1;
  23.                 totalDraws++;
  24.             }
  25.         }
  26.  
  27.         if (gamesCount == 0) {
  28.             System.out.println(String.format("%s hasn't played any games during this season.", teamName));
  29.         } else {
  30.             double winRate = totalWins * 1.0 / gamesCount * 100;
  31.  
  32.             System.out.println(String.format("%s has won %d points during this season.", teamName, totalPoints));
  33.             System.out.println("Total stats:");
  34.             System.out.println(String.format("## W: %d", totalWins));
  35.             System.out.println(String.format("## D: %d", totalDraws));
  36.             System.out.println(String.format("## L: %d", gamesCount - totalWins - totalDraws));
  37.             System.out.println(String.format("Win rate: %.2f%%", winRate));
  38.         }
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement