I am doing a 5 X 5 bingo card. Obviuosly, there are 5 rows and 5 columns. What I
ID: 3592666 • Letter: I
Question
I am doing a 5 X 5 bingo card. Obviuosly, there are 5 rows and 5 columns. What I need is to have random, non-repeating numbers per column.
Column 1 should have random, non repeating numbers from 1-15.
Column 2 should have random, non repeating numbers from 16-30.
Column 3 should have random, non repeating numbers from 31-45
Column 4 should have random, non repeating numbers from 46-60
& Column 5 should have random, non repeating numbers from 61-75.
I know how to do the grid, however, my main issue is creating random, non-repeating numbers per column. Any help will be greatly appreciated!
Explanation / Answer
Code in Java
import java.util.Random;
public class Bingo
{
Random randNum = new Random();
int[][] card_num = new int[5][5];
boolean[][] shadow = new boolean[5][5];
public Bingo()
{
for(int i = 0; i < card_num.length; i++)
{
this.card_num[i][0] = randInt(1, 15);
while(this.card_num[i][0] != card_num[i][0])
{
i++;
}
if(this.card_num[i][0] == card_num[i][0])
{
card_num[i][0] = randInt(1, 15);
}
}
for(int j = 0; j < card_num.length; j++)
{
card_num[j][1] = randInt(16, 30);
}
for(int k = 0; k < card_num.length; k++)
{
card_num[k][2] = randInt(31, 45);
card_num[2][2] = 0;
}
for(int m = 0; m < card_num.length; m++)
{
card_num[m][3] = randInt(46, 60);
}
for(int n = 0; n < card_num.length; n++)
{
card_num[n][4] = randInt(61, 75);
}
for(int i = 0; i < shadow.length; i++)
{
for(int j = 0; j < 5; j++)
{
shadow[i][j] = false;
shadow[2][2] = true;
}
}
}
private int randInt(int min, int max)
{
int random;
random = randNum.nextInt(max - min) + min;
return random;
}
public String Print_Card()
{
String string = "";
for(int row = 0; row < card_num.length; row++)
{
for(int col = 0; col < card_num[row].length; col++)
{
System.out.print(card_num[row][col] + " ");
}
System.out.println();
}
return string;
}
public static void main(String[] args)
{
Bingo bc = new Bingo();
bc.Print_Card();
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.