/** This file defines the Player class -- statistics on an individual * football player. */ import java.util.*; public class Player { private String firstName; private String lastName; private int number; private int feet; private int inches; private int weight; private int day; private int month; private int year; /** The initial value constructor takes a string parameter, and we * parse this string using Java's string tokenizer. * We'll assume a typical string will look like this: * Lloyd, Matthew 18 6-3 198 16/4/1978 */ public Player (String s) { // initialize the string tokenizer to begin with our input string, // and assume that space, comma, dash and slash are to be delimiters StringTokenizer tok = new StringTokenizer (s, " ,-/"); // the first 2 tokens are the player's name lastName = new String (tok.nextToken()); firstName = new String (tok.nextToken()); // next, read in player's number number = Integer.parseInt(tok.nextToken()); // read height, weight and birthdate just like we read in the player number feet = Integer.parseInt(tok.nextToken()); inches = Integer.parseInt(tok.nextToken()); weight = Integer.parseInt(tok.nextToken()); day = Integer.parseInt(tok.nextToken()); month = Integer.parseInt(tok.nextToken()); year = Integer.parseInt(tok.nextToken()); } /** How can we make the output look better? */ public String toString() { return "# " + number + " " + firstName + " " + lastName + " " + feet + "'" + inches + "\" " + weight + " lbs. born " + day + "/" + month + "/" + year; } }