Advertisement
marking2112

GameInfo

Nov 2nd, 2018
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.13 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class GameInfo {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         String teamName = scanner.nextLine();
  8.         int gamesCount = Integer.parseInt(scanner.nextLine());
  9.  
  10.         int totalMinutes = 0;
  11.         double averageTime = 0;
  12.         int additionalTime = 0;
  13.         int penalties = 0;
  14.  
  15.         for (int i = 0; i < gamesCount; i++) {
  16.             int gameTime = Integer.parseInt(scanner.nextLine());
  17.  
  18.             totalMinutes += gameTime;
  19.             if (gameTime > 90 && gameTime <= 120) {
  20.                 additionalTime++;
  21.             } else if (gameTime > 120) {
  22.                 penalties++;
  23.             }
  24.         }
  25.         averageTime = totalMinutes * 1.0 / gamesCount;
  26.         System.out.printf("%s has played %d minutes." +
  27.                         " Average minutes per game: %.2f%n"
  28.                 , teamName
  29.                 , totalMinutes
  30.                 , averageTime);
  31.         System.out.printf("Games with penalties: %d%n", penalties);
  32.         System.out.printf("Games with additional time: %d", additionalTime);
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement