I'm trying to print out what I inputted for my ArrayList but I keep getting weird results such as this [player@42a57993, player@75b84c92, player@6bc7c054]
when I clearly put in legitimate names. So take a look at my code and see what the problem might be:
if (o == 5) {
double RD, t, old, x;
String tournament, player;
int a, number_of_players, place;
ArrayList<player> players = new ArrayList<player>();
System.out.println("1:Add a tournament \t2:View Existing");
a = keyIn.nextInt();
if (a == 1) {
System.out.println("\nEnter tournament name");
tournament = keyIn.next();
System.out.println("\nEnter number of players");
number_of_players = keyIn.nextInt();
System.out.println("Enter players");
for (int i = 0; i < number_of_players; i++) {
String name = keyIn.next();
player plr = new player();
plr.setName(name);
players.add(plr);
}
System.out.println("Enter places for");
System.out.println(players);
place = keyIn.nextInt();
Here is my player
class:
public class player {
private static String name;
public void setName(String pName)
{
name = pName;
}
public String getName()
{
return name;
}
}
Let me know what you guys come up with! Thanks!