/** A team will simply be an array of Players */ import java.io.*; import java.util.*; public class Team { // p represents the array of players private ArrayList p; public Team() { BufferedReader kbd = new BufferedReader(new InputStreamReader(System.in)); try { System.out.print("What is the name of the input file? "); String filename = new String(kbd.readLine()); // Set up for reading from the input file BufferedReader input = new BufferedReader (new FileReader (filename)); // allocate space for all the members of the team p = new ArrayList(); // for each player, read the information from input, create the player // object, and then put it in the array // Note that here we are reading from "input" not from "kbd" because // the input is in a file. while(true) { String line = input.readLine(); if (line == null) break; Player nextPlayer = new Player(line); p.add(nextPlayer); } } catch(IOException e) { System.out.println("Input exception encountered in Team constructor."); System.exit(1); } } /** The string representation of the team will just be the concatenation * of all the players, one per line */ public String toString() { String teamString = new String(); for (int i = 0; i < p.size(); ++i) { teamString += p.get(i) + "\n"; } return teamString; } }