Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need help! I can print the bingo board but cant play the game. I need to be ab

ID: 3540841 • Letter: I

Question

I need help! I can print the bingo board but cant play the game. I need to be able to play the game.....please help!





import java.util.*;

public class Bingo{

    static ArrayList<Integer> B = new ArrayList<Integer>();

    static ArrayList<Integer> I = new ArrayList<Integer>();

    static ArrayList<Integer> N = new ArrayList<Integer>();

    static ArrayList<Integer> G = new ArrayList<Integer>();

    static ArrayList<Integer> O = new ArrayList<Integer>();

    public static int randomInt(int low, int high) {

        return (int)(Math.random() * (high - low + 1)) + low;

    }

    public static void setArrayList(ArrayList<Integer> al, int sz, int r1, int r2) {

int n;

for (int a=0; a<sz; a++) {

while (true) {

n = randomInt(r1, r2);

if (!al.contains(n)) {

al.add(n);

break;

}

}

}

    }

public static void main(String[] args) {

setArrayList(B, 5, 1, 15);

setArrayList(I, 5, 16, 30);

setArrayList(N, 4, 31, 45);

setArrayList(G, 5, 46, 60);

setArrayList(O, 5, 61, 75);

System.out.println(" B  I  N  G  O");

for (int a=0; a<5; a++) {

if (a<2)

System.out.printf("%2d %2d %2d %2d %2d ",  

B.get(a), I.get(a), N.get(a), G.get(a), O.get(a));

else if (a==2)

System.out.printf("%2d %2d %s %2d %2d ",  

B.get(a), I.get(a), "  ", G.get(a), O.get(a));

else

System.out.printf("%2d %2d %2d %2d %2d ",  

B.get(a), I.get(a), N.get(a-1), G.get(a), O.get(a));

}

}

}

Explanation / Answer

import javax.swing.*;

import java.awt.*;

public class BingoCard extends JComponent

{

class Boxes extends Rectangle

{

public int owner;

public String Sowner;

public Boxes()

{

owner = 0;

Sowner = "" + owner;

}

}

public Boxes[][] board = new Boxes[5][5];

public BingoCard()

{

for (int i = 0; i < 5; i++)

{

for (int k = 0; k < 5; k++)

{

board[i][k] = new Boxes();

board[i][k].height = 50;

board[i][k].width = 50;

board[i][k].x = (k * 50)+ 50;

board[i][k].y = (i * 50) + 50;

}

}

}

public void paintComponent(Graphics g)

{

Graphics2D g2 = (Graphics2D) g;

for(int i = 0; i < 5; i++)

{

for(int k = 0; k < 5; k++)

{

g2.draw(board[i][k]);

if(board[i][k].owner != 0)

{

int x = board[i][k].x;

int y = board[i][k].y;

g2.drawString(board[i][k].Sowner, x+25, y+25);

}

}

}

}

}