/*
 * MLB2.java
 *
 * Date: June 7, 2015
 */

import java.util.*;
import java.io.*;

public class MLB2 {
    public static final String FILENAME = "mlb.txt";

    public static void main(String args[])
            throws FileNotFoundException {
        Scanner console = new Scanner(System.in);

        System.out.println("*** Team Statistics Finder ***");

        String teamName;
        do {
            System.out.println();
            System.out.print("Enter team name (or q to quit): ");
            teamName = console.nextLine();
            if (teamName.equals("q")) {
                break;
            }
            searchByTeamName(teamName);
        } while (true);
    }

    /*
     * Searches for the specified team name in the data file and,
     * if it is found, print the relevant data. If the team name
     * is not found, print the appropriate message.
     */
    public static void searchByTeamName(String teamName)
            throws FileNotFoundException {
        Scanner input = new Scanner(new File(FILENAME));

        boolean found = false;

        while (input.hasNextLine()) {
            String record = input.nextLine();
            String[] fields = record.split("\t");

            String name = fields[0];

            if (teamName.equals(name)) {
                found = true;
                System.out.println("Team\tW\tL\tPCT\tGB");
                System.out.println(record);
            }
        }

        if (!found) {
            System.out.println("Could not find team \"" + teamName + "\"!");
        }

    }
}