thecoderenroute

Untitled

Apr 19th, 2020
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.44 KB | None | 0 0
  1.  
  2. import java.nio.file.Paths;
  3. import java.util.ArrayList;
  4. import java.util.Scanner;
  5.  
  6. public class SportStatistics {
  7.  
  8.     public static void main(String[] args) {
  9.         Scanner scan = new Scanner(System.in);
  10.         System.out.println("File: ");
  11.         String file = scan.nextLine();
  12.         System.out.println("Team: ");
  13.         String team = scan.nextLine();
  14.         int games = 0, wins = 0, loss = 0;
  15.         try (Scanner read = new Scanner(Paths.get(file))) {
  16.             while (read.hasNextLine()) {
  17.                 String line = read.nextLine();
  18.                 String[] stats = line.split(",");
  19.                 if (stats[0].equals(team)) {
  20.                     games++;
  21.                     if (Integer.valueOf(stats[2]) > Integer.valueOf(stats[3])) {
  22.                         wins++;
  23.                     } else {
  24.                         loss++;
  25.                     }
  26.                 } else if (stats[1].equals(team)) {
  27.                     games++;
  28.                     if (Integer.valueOf(stats[3]) > Integer.valueOf(stats[2])) {
  29.                         wins++;
  30.                     } else {
  31.                         loss++;
  32.  
  33.                     }
  34.                 }
  35.             }
  36.         } catch (Exception e) {
  37.             System.out.println("Error: " + e.getMessage());
  38.         }
  39.         System.out.println("Games: "+games);
  40.         System.out.println("Wins: "+wins);
  41.         System.out.println("Losses: "+loss);
  42.  
  43.     }
  44.  
  45. }
Add Comment
Please, Sign In to add comment