I have a program with 2 classes. The player class that contains only the name attribute:
public class player {
String name;
}
And I have the Main class that has the function below and the same call in main
Public class Principal{
public static void setPlayers(int valor){
int i;
for(i=0;i<valor;i++){
player[] vetor = new player[valor];
vetor[i] = new player();
}
}
public static void main(String[] args) {
System.out.println("Insira a quantidade de jogadores de 1 a 4");
int n = 4;
}
}
Now the doubt, I created 4 players and I want to put their names or get their names. What call should I make on main? I tried this one below and it says that the vector does not exist
vetor[0].getName();
For the exercise I'm doing, I need to store an X amount of players and change / pick their names. So I had to manipulate the data from that vector