Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.nio.file.Paths;
- import java.util.ArrayList;
- import java.util.Scanner;
- public class SportStatistics {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- System.out.println("File: ");
- String file = scan.nextLine();
- System.out.println("Team: ");
- String team = scan.nextLine();
- int games = 0, wins = 0, loss = 0;
- try (Scanner read = new Scanner(Paths.get(file))) {
- while (read.hasNextLine()) {
- String line = read.nextLine();
- String[] stats = line.split(",");
- if (stats[0].equals(team)) {
- games++;
- if (Integer.valueOf(stats[2]) > Integer.valueOf(stats[3])) {
- wins++;
- } else {
- loss++;
- }
- } else if (stats[1].equals(team)) {
- games++;
- if (Integer.valueOf(stats[3]) > Integer.valueOf(stats[2])) {
- wins++;
- } else {
- loss++;
- }
- }
- }
- } catch (Exception e) {
- System.out.println("Error: " + e.getMessage());
- }
- System.out.println("Games: "+games);
- System.out.println("Wins: "+wins);
- System.out.println("Losses: "+loss);
- }
- }
Add Comment
Please, Sign In to add comment