我正在尝试显示我创建的对象的各个元素。
它是一个简单的 Java 程序,允许用户添加和跟踪播放器详细信息。
在添加细节后显示细节时,我感到很困惑。这是我的代码的样子
我可以使用案例 2 创建对象并将其输入到数组列表中没有问题,但是当我尝试将其打印出来时,我想做类似的事情
System.out.println("Player Name" + myPlayersArrayList.PlayerName + "Player Position" + myPlayerArrayList.PlayerPosition + "Player Age" + "Player Age");
我知道这是不正确的,但我真的不知道该怎么做,如果有人可以提供任何帮助,将不胜感激。谢谢
System.out.println("Welcome to the Football Player database");
System.out.print(System.getProperty("line.separator"));
UserInput myFirstUserInput = new UserInput();
int selection;
ArrayList<Player> myPlayersArrayList = new ArrayList<Player>();
while (true) {
System.out.println("1. View The Players");
System.out.println("2. Add A Player");
System.out.println("3. Edit A Player");
System.out.println("4. Delete A Player");
System.out.println("5. Exit ") ;
System.out.print(System.getProperty("line.separator"));
selection = myFirstUserInput.getInt("Please select an option");
System.out.print(System.getProperty("line.separator"));
switch(selection){
case 1:
if (myPlayersArrayList.isEmpty())
{
System.out.println("No Players Have Been Entered Yet");
System.out.print(System.getProperty("line.separator"));
break;}
else
{for(int i = 0; i < myPlayersArrayList.size(); i++){
System.out.println(myPlayersArrayList);
}
break;
case 2: {
String playerName,playerPos;
int playerAge;
playerName = (myFirstUserInput.getString("Enter Player name"));
playerPos = (myFirstUserInput.getString("Enter Player Position"));
playerAge = (myFirstUserInput.getInt("Enter Player Age"));
myPlayersArrayList.add(new Player(playerName, playerPos, playerAge)); ;
break;
}