Lab 02


DUE DATE CHANGE: For Professor Fleck's class this lab will be due Sept 22.
DUE DATE:    This lab must be completed by Saturday, 10:30am, September 15th. Note: After the first few labs, labs will be due on the Saturday of the week they are assigned. Because students sometimes enroll late, have account problems, etc.,  the first 2 labs are due on the same date. You are encouraged to do them, one per week, and submit each as you complete it. Ask your TA to verify that your lab was submitted correctly, and get his/her help if need be before the deadline.

OBJECTIVE:

Use Netbeans to create a full Java application and review Java File I/O and Java Swing.

GRADING

Total 10 points

PREPARATION:

You should have Netbeans available and running on your computer for this lab.

Download and read the file: players.txt

BACKGROUND:

If needed read through the Java review (chapter 1 in our book). Additionally you may want to review the Java slides (Ch 01) from the syllabus. 

ASSIGNMENT:

You are running a Soccer Team league. The league has provided you with a textfile (see link in preparation above) containing all the players and team names. You must read in the teams, add players to the appropriate team and then ask the user which team roster they would like to see and print that out to a text file.

Classes you create
You should create 3 classes for this assignment.

Player class - Hold information about a single Player. The toString() method should be overriden to return a String representing all information about this player.

Team class - This class should contain the team name and a Collection of players.

Controller class - The controller is the main program that reads in the file and creates the players and teams.

Sample Input file format
The sample input file has a single line for each player. The player's attributes are separated by tildes (~). You must read in each line and create a player and (if needed) a new team.

Format:
Player Name~Player Position~Player height~Player weight~Player hometown~Team name

For example:
    Berhalter, Gregg~Defense~6'1"~175~Tenafly, N.J.~1860 Munich (Germany)
    Bocanegra, Carlos~Defense~6'0"~170~Alto Loma, Calif.~Fulham FC (England)
    Boswell, Bobby~Defense~6'1"~185~Tampa, Fla. ~D.C. United (MLS)

Sample pseudocode to implement for the controller is below:

// Ask the user for the filename of the team list
// Hint: use the Scanner class here

// Open the file (check the javadocs for BufferedReader)

// while lines are still available
    //  read line
    //  tokenize the line (use the StringTokenizer.. but change the delimeter to '~')
    //  create a player object based on the tokens
    //  if the player's team does not exist, create the team
    //  add the player to the team
    //  close the file

// Ask the user which team roster to print (from the teams that exist)

// Ask the user for a filename to write the team roster to

// Create the team roster output file
//  The output file uses padded strings to ensure all the data shows up in columns.
//  To format a String for column output you can use the String.format method. 
//  String outputString = String.format("%30s %20s %10s %10d %40s", name, position, height, weight, hometown)


Output File
The output file should look roughly like this:

Team Name: D.C. United (MLS)
Number of players: 22
=================================================
Name                Position    Height    Weight                 Hometown
Gros, Joshua        Midfield      6'1"       165        Mechanicsburg, Pa
Adu, Freddy         Midfield      5'8"       140              Potomac, Md.
...

What to turn in
You should turn in a Jar file including all your source code and compiled Java program.

In Netbeans to include your source code:
  1. Right click on your project name (in the projects window)
  2. Select properties
  3. Select Build->Packaging
  4. Remove everything in the "Exclude from Jar" texfield.
  5. Click ok.
  6. When you build the software the Jar file created in <<project name>>/dist/<<project name>>.jar will include the source and compiled Java classes. This is the file to turn in.
    How you should customize your Netbeans to save source code