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

Bingo A Bingo card consists of 5 columns and 5 rows. Each column has a range of

ID: 3678195 • Letter: B

Question

Bingo

A Bingo card consists of 5 columns and 5 rows. Each column has a range of numbers from which the spaces in that column can be populated:

Column 0 (the ‘B’ column): 1-15

Column 1 (the ‘I’ column): 16-30

Column 2 (the ‘N’ column): 31-45

Column 3 (the ‘G’ column): 46-60

Column 4 (the ‘O’ column): 61-75

No number is repeated in any column. The center space is considered a free space and has no number (it is considered automatically marked).

In a game of Bingo, numbers are called randomly, and those numbers apply to all cards in play. Any cards in play may mark any number that is called if it appears on that card. It is common to call bingo numbers with the letter of their column, such as B-12, but this is not necessary, since a 12 can only be in the B column.

The first card that marks a complete line of spaces either horizontally, vertically, or diagonally wins immediately.

Implement the following class for a bingo card. The methods shown are a minimum requirement. You may add additional methods if you wish. BingoCard

-cardNumbers: int [][]

-cardMarks: boolean [][]

-calls: int []

-callsMade: int

An array that holds the numbers on the card. The free space has a value 0.

An array that holds Boolean values. A true means that the corresponding number in cardNumbers has been called.

An array that holds all the numbers that have been called in sequence, whether they appear on this card or not. This is a static instance variable.

The number of calls that are actually stored in the calls array. This is a static instance variable.

+BingoCard()

+BingoCard(numbers: int [][])

-setNumber(number: int,

row: int, col:int): void

+getCardNumbers(): int [][]

+getCardmarks(): boolean [][]

+markCard(): void

+isBingo(): Boolean

+setCalls(int []): void

+getCalls(): int []

+addCall(int callNumber): void

Constructs a BingoCard filled with random numbers (as allowed by Bingo), and then marks the card.

Constructs a BingoCard from a two-dimensional array of integers, and then marks the card.

Sets the number in a particular space on the card to the desired value. It should display an error and set the space to -1 if the number is invalid for that space.

Returns the two-dimensional array of integers appearing on the card.

Returns the two-dimensional array of marks made on the card.

Updates the card marks by going through the list of called numbers.

Returns true if any card marks make a horizontal, vertical, or diagonal line on the card.*

Sets the sequence of numbers that have been called in the game.

Returns the sequence of numbers that have been called in the game.

Adds a number to the list of called numbers. This is a static method.

* There may not be more than two statements using array indices which do not change.

You will be provided with BingoCardTest.java, which will provide all necessary testing for the minimum required methods given above. If you add additional methods, you ought to write tests for them so that you can trust their correct operation.

You do need to provide documentation for your class, but much of it is provided in the explanation above. It is recommended that you write your Javadoc comments before you write

test for such a program is bellow:

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import java.io.*;
import java.util.Vector;
import java.util.Iterator;

/**
* This class contains tests for another program.
*
* @author Student Name - section 000
* @version Date of Submission
*/
public class BingoCardTest
{
    /** Text output to the console. */
    ByteArrayOutputStream outputStream;
   
    /** Vector built from sends */
    Vector<String> sends = new Vector<String>();

    /** Vector built from expects */
    Vector<String> expects = new Vector<String>();

    /** Vector built from expects for comparing expect strings to output
      * strings. It is consumed during use.
      */
    Vector<String> chkExpects = new Vector<String>();
   
    /** String used to to compare expect strings to output strings.
      * It is consumed during use.
      */
    String outputChkString = "";

    /** Fixture initialization (common initialization for all tests). */
    @Before public void setUp()
    {
        /* Exercise console I/O methods so that WebCat doesn't count them as
           untested. */
        expect("");
        send("");
        getNextExpected();
        getNextActual();

        /* Common starting code for all tests goes here */
    }

    /** Prepares a string to be part of the standard input. It also sets
      * the console input to be all the send strings that have been
      * entered thus far.
      *
      * @param textToSend The string to add to the planned input.
      */
    void send(String textToSend)
    {
        sends.add(textToSend);      
        setUpConsoleInput();
    }
   
    /** Redirects console input to come from the sends, rather than the
      * console.
      */
    void setUpConsoleInput()
    {
        System.setIn(
            new ByteArrayInputStream(sendString().getBytes()));
    }

    /** Converts all the sent strings into a single continuous string and
      * returns it.
      *
      * @return All the sent strings concatenated together.
      */
    String sendString()
    {
        String result = "";
        Iterator sendItr = sends.iterator();
        while (sendItr.hasNext())
        {
            result += sendItr.next();
        }
        return result;
    }
   
    /** Adds a string to the expected output. It also prepares the console
      * output to be captured for later use.
      *
      * @param textToExpect A string that will be added to the expected output.
      */
    void expect(String textToExpect)
    {
        expects.add(textToExpect);
        chkExpects.add(textToExpect);
        captureConsoleOutput();
    }

    /** Redirects console output such that the resulting output is available in
     * the outputText instance variable of this testing class. **/
    void captureConsoleOutput()
    {
        outputStream = new ByteArrayOutputStream();
        PrintStream printStream = new PrintStream(outputStream);
        System.setOut(printStream);
    }
   
    /** Returns the next string that is expected to come from standard
      * output.
      *
      * @return The next string expected from standard output.
      */
    String getNextExpected()
    {
        if (!chkExpects.isEmpty())
        {
            return chkExpects.get(0);
        }
        else
        {
            return "";
        }
    }
   
    /** Returns the next string that actually came from standard output.
      * The length of the string retrieved is based on the length of
      * the string that was expected at this point.
      *
      * @return The next string received from standard output.
      */
    String getNextActual()
    {
        if (!chkExpects.isEmpty())
        {
            if (outputChkString.equals(""))
            {
                outputChkString = outputStream.toString().replace(" ", " ");
            }
            String expect = chkExpects.remove(0).trim();
            String output =
                outputChkString.substring(0, expect.length()).trim();
            outputChkString = outputChkString.substring(expect.length()).trim();
            return output;
        }
        else
        {
            return "";
        }
    }
   
    /** Test whether a good card is created as specified. */
    @Test public void testSpecifiedGoodCard()
    {
        int [][] cardNumbers =
        {
            { 7, 16, 36, 46, 66},
            { 8, 24, 33, 53, 62},
            { 1, 23, 0, 54, 63},
            {10, 19, 34, 57, 61},
            {12, 17, 31, 49, 73}
        };
        BingoCard card = new BingoCard(cardNumbers);
        for (int row = 0; row < 5; row++)
        {
            for (int col = 0; col < 5; col++)
            {
                Assert.assertEquals("Number at row " + row + " and column " +
                    col + " is not as specified",
                    cardNumbers[row][col], card.getCardNumbers()[row][col]);
            }
        }
    }
   
    /** Test whether a bad card is created as specified, and its errors are
     * caught.
     */
    @Test public void testSpecifiedBadCard()
    {
        int [][] cardNumbers =
        {
            { 7, 16, 36, 46, 66},
            { 8, 24, 33, 53, 62},
            { 1, 23, 42, 54, 63},
            {10, 19, 34, 57, 59},
            { 8, 17, 31, 49, 73}
        };
        BingoCard card = new BingoCard(cardNumbers);
        Assert.assertEquals("Duplicate number not found", -1,
            card.getCardNumbers()[4][0]);
        Assert.assertEquals("Middle space is not 0 (free)", -1,
            card.getCardNumbers()[2][2]);
        Assert.assertEquals("Invalid number not found in O column", -1,
            card.getCardNumbers()[3][4]);
    }

    /** Test whether a random card is created correctly. */
    @Test public void testRandomCard()
    {
        BingoCard card = new BingoCard();
        Assert.assertEquals("Middle space is not 0 (free)", 0,
            card.getCardNumbers()[2][2]);
        for (int col = 0; col < 5; col++)
        {
            for (int row = 0; row < 5; row++)
            {
                if (col != 2 && row != 2)
                {
                    Assert.assertTrue("Invalid number found in column " + col,
                        card.getCardNumbers()[row][col] >= col * 15 + 1 &&
                        card.getCardNumbers()[row][col] <= col * 15 + 15);
                }
                for (int otherRow = row + 1; otherRow < 5; otherRow++)
                {
                    Assert.assertTrue("Duplicate number found in column " +
                        col,
                        card.getCardNumbers()[row][col] !=
                        card.getCardNumbers()[otherRow][col]);
                }
            }
        }
    }
   
    /** Test whether the sequence of called numbers is correctly created. */
    @Test public void testSetCalls()
    {
        int [] testCalls = {24, 76, 57, 30, -1, 31};
        BingoCard.setCalls(testCalls);
        Assert.assertEquals("setCalls did not set a specified call", 24,
            BingoCard.getCalls()[0]);
        Assert.assertEquals("setCalls did not set a specified call", 57,
            BingoCard.getCalls()[1]);
        Assert.assertEquals("setCalls did not set a specified call", 30,
            BingoCard.getCalls()[2]);
        Assert.assertEquals("setCalls did not set a specified call", 31,
            BingoCard.getCalls()[3]);
    }
   
    /** Test whether a call is added to the sequence of called numbers
     * correctly.
     */
    @Test public void testAddCall()
    {
        BingoCard.addCall(24);
        Assert.assertEquals("setCalls did not set a specified call", 24,
            BingoCard.getCalls()[0]);
        int [] testCalls = {24, 57, 30, 31};
        BingoCard.setCalls(testCalls);
        BingoCard.addCall(-1);
        BingoCard.addCall(76);
        BingoCard.addCall(50);
        Assert.assertEquals("setCalls did not set a specified call", 24,
            BingoCard.getCalls()[0]);
        Assert.assertEquals("setCalls did not set a specified call", 50,
            BingoCard.getCalls()[4]);
    }
   
    /** Test whether a card is marked correctly, according to the sequence of
     * called numbers provided.
     */
    @Test public void testMarkCard()
    {
        int [][] cardNumbers =
        {
            { 7, 16, 36, 46, 66},
            { 8, 24, 33, 53, 62},
            { 1, 23, 0, 54, 63},
            {10, 19, 34, 57, 61},
            {12, 17, 31, 49, 73}
        };
        BingoCard card = new BingoCard(cardNumbers);
        BingoCard.addCall(57);
        card.markCard();
        Assert.assertTrue("G-57 not marked correctly",
            card.getCardMarks()[3][3]);
        int [] testCalls = {57, 1, 17, 36, 73};
        BingoCard.setCalls(testCalls);
        card.markCard();
        Assert.assertTrue("B-1 not marked correctly",
            card.getCardMarks()[2][0]);
        Assert.assertTrue("N-36 not marked correctly",
            card.getCardMarks()[0][2]);
        Assert.assertTrue("O-73 not marked correctly",
            card.getCardMarks()[4][4]);
        Assert.assertTrue("I-17 not marked correctly",
            card.getCardMarks()[4][1]);
        Assert.assertTrue("Free Space not marked correctly",
            card.getCardMarks()[2][2]);
        Assert.assertTrue("G-57 not marked correctly",
            card.getCardMarks()[3][3]);
    }
   
    /** Test whether different types of bingos or non-bingos are correctly
     * recognized.
     */
    @Test public void testBingos()
    {
        int [][] cardNumbers =
        {
            { 7, 16, 36, 46, 66},
            { 8, 24, 33, 53, 62},
            { 1, 23, 0, 54, 63},
            {10, 19, 34, 57, 61},
            {12, 17, 31, 49, 73}
        };
        BingoCard card = new BingoCard(cardNumbers);
        Assert.assertTrue("Non-bingo not recognized", !card.isBingo());
        int [] testCalls = {57, 1, 17, 36, 73};
        BingoCard.setCalls(testCalls);
        card.markCard();
        Assert.assertTrue("Non-bingo not recognized", !card.isBingo());
        testCalls = new int [] {7, 10, 57, 73, 24};
        BingoCard.setCalls(testCalls);
        card.markCard();
        Assert.assertTrue("Diagonal bingo not recognized", card.isBingo());
        testCalls = new int [] {36, 19, 12, 66, 57, 53};
        BingoCard.setCalls(testCalls);
        card.markCard();
        Assert.assertTrue("Diagonal bingo not recognized", card.isBingo());
        testCalls = new int [] {10, 19, 34, 61, 57};
        BingoCard.setCalls(testCalls);
        card.markCard();
        Assert.assertTrue("Horizontal bingo not recognized", card.isBingo());
        testCalls = new int [] {16, 36, 24, 57, 23, 17, 61, 19};
        BingoCard.setCalls(testCalls);
        card.markCard();
        Assert.assertTrue("Vertical bingo not recognized", card.isBingo());
        testCalls = new int [] {7, 57, 54, 34, 24, 73, 10, 46, 19, 53, 49, 61};
        BingoCard.setCalls(testCalls);
        card.markCard();
        Assert.assertTrue("Multiple bingo not recognized", card.isBingo());
    }
}

Implement the following class for a bingo card. The methods shown are a minimum requirement. You may add additional methods if you wish. BingoCard

-cardNumbers: int [][]

-cardMarks: boolean [][]

-calls: int []

-callsMade: int

An array that holds the numbers on the card. The free space has a value 0.

An array that holds Boolean values. A true means that the corresponding number in cardNumbers has been called.

An array that holds all the numbers that have been called in sequence, whether they appear on this card or not. This is a static instance variable.

The number of calls that are actually stored in the calls array. This is a static instance variable.

+BingoCard()

+BingoCard(numbers: int [][])

-setNumber(number: int,

row: int, col:int): void

+getCardNumbers(): int [][]

+getCardmarks(): boolean [][]

+markCard(): void

+isBingo(): Boolean

+setCalls(int []): void

+getCalls(): int []

+addCall(int callNumber): void

Constructs a BingoCard filled with random numbers (as allowed by Bingo), and then marks the card.

Constructs a BingoCard from a two-dimensional array of integers, and then marks the card.

Sets the number in a particular space on the card to the desired value. It should display an error and set the space to -1 if the number is invalid for that space.

Returns the two-dimensional array of integers appearing on the card.

Returns the two-dimensional array of marks made on the card.

Updates the card marks by going through the list of called numbers.

Returns true if any card marks make a horizontal, vertical, or diagonal line on the card.*

Sets the sequence of numbers that have been called in the game.

Returns the sequence of numbers that have been called in the game.

Adds a number to the list of called numbers. This is a static method.

Explanation / Answer

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();

    }


}