Я declate многомерной массиву propertyArray = new int[numbHuman][40]
Как передать многомерный массив в конструкторы?
[numbHuman]
, где это число строк, а [40]
это количество столбцов (или наоборот реально не имеет значения). В любом случае я создаю те свойстваArray в вложенном цикле, но я не уверен, как передать свойствоArray [] [] в конструктор объекта игрока. Вот мой код, я попробую уточнить, если это необходимо.
import java.util.Scanner;
import java.util.Random;
public class PlayerArray
{
Scanner scan = new Scanner(System.in);
private int numbHuman;
private Player[] arr;
private String[] userName;
//private
private int[] testArray;
private int[][] propertyArray;
private int[] userID;
private int startingMoney;
private int startingPosition;
private int b;
private int c;
private int i;
//private int d;
public PlayerArray()
{
Scanner scan = new Scanner(System.in);
System.out.println("How many players wish to play? Values of 2 through 8 accepted.");
numbHuman = scan.nextInt();
System.out.println(numbHuman + " players selected.");
while (numbHuman < 2 || numbHuman > 8)
{
System.out.println("Invalid entry, try again.");
numbHuman = scan.nextInt();
}
arr = new Player[numbHuman];
i=0;
testArray = new int[40];
propertyArray = new int[numbHuman][40];///// WORK ON DIS
userName = new String[numbHuman];
userID = new int[numbHuman];
startingMoney = 1500;
startingPosition = 0;
b=0;
c=0;
for(int i = 0; i < arr.length; i++)
{
userID[i] = b;
System.out.println("Player " + (i + 1) + ", Please enter your first name:");
userName[i] = scan.next();
for(c = 0; c < 40; c++)
{
propertyArray[i][c] = 0;
}
arr[i] = new Player(userName[i],startingMoney,userID[i],startingPosition,propertyArray[i][c]);
b++;
}
}
Я пытаюсь передать его, как я могу это сделать? Все остальные переменные работают, но многомерный массив.
public Player(String userName, int changeInMoney, int userID, int startingPosition, int[][]propertyArray)
{
myID = userID;
myName = userName;
currentPosition += startingPosition;
currentBal -= payBank(changeInMoney);
}
Side Примечание: это может быть лучше * not *, чтобы обеспечить все входящие приглашения внутри самого массива. – ChiefTwoPencils
EDIT только что обновил последние строки первого класса. –