I'm making a bingo programme. I currently just want to make the 2D array representing the numbers on the bingo card. Column 1 can only contain 1-15 Column 2 16-30 Column 3 31-45 etc....
This is my code so far and sometimes it throws an exception but sometimes it doesn't which is weird.
private int[][] bingoCard = new int [5][5];
public BingoCard()
{
int [][]bingoCardInit = new int [5][5];
bingoCard = bingoCardInit;
}
public void fillInCard()
{
int arrayIndex = 0;
Integer[] arr = new Integer[16];
for (int i = 1; i <= 15; i++)
{
arr[i] = i;
}
Collections.shuffle(Arrays.asList(arr));
for(int rowIndex = 0; rowIndex<5; rowIndex++)
{
bingoCard[0][rowIndex] = arr[rowIndex];
System.out.println(bingoCard[0][rowIndex]);
}
Integer[] arr1 = new Integer[16];
for (int i = 16; i <= 30; i++)
{
arr1 [arrayIndex]= i;
arrayIndex++;
}
Collections.shuffle(Arrays.asList(arr1));
arrayIndex = 0;
for(int rowIndex = 0; rowIndex<5; rowIndex++)
{
bingoCard[1][arrayIndex] = arr1[rowIndex];
System.out.println(bingoCard[1][arrayIndex]);
arrayIndex++;
}
arrayIndex = 0;
Integer[] arr2 = new Integer[16];
for (int i = 31; i <= 45; i++)
{
arr2 [arrayIndex]= i;
arrayIndex++;
}
Collections.shuffle(Arrays.asList(arr2));
arrayIndex = 0;
for(int rowIndex = 0; rowIndex<5; rowIndex++)
{
bingoCard[2][arrayIndex] = arr2[rowIndex];
System.out.println(bingoCard[2][arrayIndex]);
arrayIndex++;
}
arrayIndex = 0;
Integer[] arr3 = new Integer[16];
for (int i = 46; i <= 60; i++)
{
arr3 [arrayIndex]= i;
arrayIndex++;
}
Collections.shuffle(Arrays.asList(arr3));
arrayIndex = 0;
for(int rowIndex = 0; rowIndex<5; rowIndex++)
{
bingoCard[3][arrayIndex] = arr3[rowIndex];
System.out.println(bingoCard[3][arrayIndex]);
arrayIndex++;
}
}
I'm just wondering why it sometimes throws an exception. Thank you
Aucun commentaire:
Enregistrer un commentaire