Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class FootballTournament_04 {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String teamName = scanner.nextLine();
- int countMatches = Integer.parseInt(scanner.nextLine());
- if (countMatches == 0) {
- System.out.printf("%s hasn't played any games during this season.", teamName);
- } else {
- int totalPoints = 0; //брой спечелени точки
- int countWins = 0; //брой победи
- int countDraws = 0; //брой равенства
- int countLoses = 0; //брой загуби
- for (int match = 1; match <= countMatches; match++) {
- String result = scanner.nextLine(); // "W", "D" и "L"
- switch(result) {
- case "W":
- totalPoints += 3;
- countWins++;
- break;
- case "D":
- totalPoints += 1;
- countDraws++;
- break;
- case "L":
- countLoses++;
- break;
- }
- }
- System.out.printf("%s has won %d points during this season.%n",teamName , totalPoints);
- System.out.println("Total stats:");
- System.out.printf("## W: %d%n", countWins);
- System.out.printf("## D: %d%n", countDraws);
- System.out.printf("## L: %d%n", countLoses);
- double percentWins = countWins * 1.0 / countMatches * 100;
- System.out.printf("Win rate: %.2f%%", percentWins);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment