Need help creating a bingo card and bingo in java using a 2d array that is 5x5.
ID: 3659663 • Letter: N
Question
Need help creating a bingo card and bingo in java using a 2d array that is 5x5. This is what I have so far for the bingo card java, I havnt done the game java yet cause I cant seem to get the isBingo method working for checking for bingo. This I what I have so far for the bingo card.
class BingoCard{
private int[][] card;
private boolean [][] mark;
public BingoCard(){
card = new int[5][5];
for(int r = 0; r < 5; r++){
for(int c = 0; c < 5; c++){
card[r][c] = (int)((Math.random()*100)/2 + 1);
}
}
mark = new boolean[5][5];
for(int r = 0; r < 5; r++){
for(int c = 0; c < 5; c++){
mark[r][c] = false;
}
}
}
public void display(){
for(int r = 0; r < 5; r++){
for(int c = 0; c < 5; c++){
System.out.print(card[r][c] + " ");
}
System.out.println("");
}
for(int r = 0; r < 5; r++){
for(int c = 0; c < 5; c++){
System.out.print(mark[r][c] + " ");
}
System.out.println("");
}
}
public void mark(int number){
for(int r = 0; r < 5; r++){
for(int c = 0; c < 5; c++){
if(card[r][c] == number){
mark[r][c] = true;
}
}
}
}
public boolean isBingo(){
boolean bingo = false;
int count1, count2;
count1 = 0;
count2 = 0;
for(int i = 0; i < mark.length; i++){
for(int j = 0; j < mark.length; j++){
if(mark[i][0] == true){
count1++;
}
if(mark[0][j] == true){
count2++;
}
}
}
if(count1 == 5){
bingo = true;
}
if(count2 == 5){
bingo = true;
}
return bingo;
}
}
Explanation / Answer
/** * @(#)bingoGame.java * * bingoGame application * * @author * @version 1.00 2008/11/24 */ import java.util.*; import java.math.*; public class bingoGame { public static void main(String[] args) { int i ,j; int[][] card1 = new int[5][5]; int[][] check = new int[5][5]; cardRead(card1); cardPrint(card1); random(check); } public static void cardRead(int[][]a){ int i,j; Scanner keyboard = new Scanner(System.in); System.out.print("Whats the card: "); for(i=0; iRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.