So I have my constructor in this class called Player where each player is an array of 5 (to store their bets in another class):
public class Player {
private int[] anyplayer = new int[5];
// constructor for each player at the table
public Player(int[] anyplayer) {
this.anyplayer = anyplayer;
}
Now I've unknowingly coded my other class to this:
int[] player2 = new int[5]; // this is a variable I'm trying to change to the object
try{
for(int i=0;i<5;i++) {
player2[i] = Integer.parseInt(keyin.nextLine());
}
}
catch(NumberFormatException e){
System.out.println("Player 3 : ");
}
Now I can't seem to find a workaround this without breaking everything! I'm still a newbie at programming, but is there a simple way I could replace the int[] player2 = new int[5]; with an actual object from my constructor like Player player2 = new player(); ?
I've tried that and it keeps saying The constructor Player() is undefined
constructor Player() is undefinedmeans exactly that. You haven't created a constructor method in thePlayerclass, which doesn't take an argument.