Random automation of sports teams (things) using arrays, scanners, and randomNumbers
So I was inspired by an example in my java 2 textbook and I have an idea for a java program but I'm not sure what the best approach would be. The example in the book is a program that deals a deck of 52 regular playing cards in a random order until the deck is empty using card objects.
Basically I want to start with a plain .txt file of names of hockey players (up to a couple hundred) for the current year along with a single character representing their position played. Also, I'm assuming that each name is a unique entry. There would be no chance of duplicates. For instance a file named "players2011.txt" might contain:
James Smith C
Tony Watson F
Sam Thompson G
Ok, with that in mind I want to randomly draw 1 center (let's say, C), 2 forwards, 2 defensemen, and 1 goalie from all of the players in the league (in the .txt file). This could be the active team on the ice. I would have a scanner object read each line of the .txt file into arrays based on the last character in the line (C, F, G, ...).
So the output could be:
Frank Lewis C
Tony Watson F
Aaron Miller F
Larry Fisher D
Eric Gibson D
Bobby Sanders G
..but with random players names each time using the same sequence of positions.
My thoughts are, can I make a regular array object for each position and draw a player randomly from each as needed? After playing with it a little I found it is a little tricky to declare arrays without first knowing the size. Meaning how can I make an array of goalies if I don't know the number of goalies in the text file (this will vary year to year)? (Assume that I will have a new .txt file for each year.)