2
I have a program with 2 classes. The player class contains only the name attribute:
public class player {
String name;
}
And I have the Main Class that has the function below and the call of the same in the 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 want to put their name or get their names. What call should I make in 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 this vector
The class
Principalwould be the game ? And why doesn’t it have the vector of players ? Better would be up to aArrayList<Player>to be easy to manage the amount of players you have.vetor[0].getName();doesn’t work because you have no methodgetNamein classPlayer.– Isac