Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial


Zesheng Li
Zesheng Li
3,013 Points

Soccer League Organizer Stuck on adding player to a team.

public void addPlayerToTeam() throws IOException{ List<String> firstNameList = new ArrayList<>(); List<String> lastNameList = new ArrayList<>(); String firstName; String lastName; int height; boolean exp;

    System.out.println("Players choose a team");
    team = mReader.readLine();
    System.out.println("Here is the free agent you can choose: ");
        System.out.println("Please Enter the First Name of the Player: ");
        firstName = mReader.readLine().toLowerCase();
            System.out.println("Can not fine first name. ");

        System.out.println("Please enter the Last Name of the Player: ");
        lastName = mReader.readLine().toLowerCase();
            System.out.println("Can not fine last name. ");

    List<Player> temp = new ArrayList();

Here is the code so far. I am stuck on how to get the rest of the information of the player that is selected. Some one please help.

3 Answers

honestly not to bash, but i would have used a map instead of an array list. but:

private List<Players> team;
Player[] players = Players.load();
public void pickAPlayer(String firstorlastName) {
     for ( Player player : players ) {
         String fname = player.getFirstName();
         String lname = player.getLastName();
         String fullName = lname + ", " fname;
              if(fullname.contains(firstorlastName) {

Zesheng Li
Zesheng Li
3,013 Points

I see what you mean. this helps a lot than you so much.

happy to help and jog my brain for practice :D

can you post all pages of your code please

Zesheng Li
Zesheng Li
3,013 Points

https://github.com/lzcscofield/TreeHouseSoccerLeague here, you can see all my file. So what I want is to add the player to team if one player is chosen by user. the players is a string[] type. how can I add all the data into a list.

Thank you so much.

change players to a

import java.util.Map;
import java.util.TreeMap;
import java.util.List;

Map<String fullName, Player players> playersForPicking = new TreeMap<>; 

so that you can call a player and its an object of Player, so you can use the gets. i updated. this sounds like you need a map of players, each player object will be represented by the combenation of

String fullName = lastName + ", " + firstName;

call it by

Player newPlayer = playersForPicking.get(fullName); //returns the Player object instance of that player
List<Player> team;
Zesheng Li
Zesheng Li
3,013 Points

hi, so for player it have different type string, string,int and boolean. for example there are a player ("Joe", "Smith", 42, true) how do I search firstName and lastName and than it will return me whole data?