Results 1 to 2 of 2
  1. #1
    08cmoss is offline Member
    Join Date
    Sep 2012
    Rep Power

    Default Bingo cover() method not working. Help!

    I have written all the code for my Bingo game to work, but my cover() method in BingoCard is not working. I have gotten rid of the null pointer exception when comparing the two strings. But regardless the cover() method will not work. I have attached the code below and below that is the code to make the whole thing work.
    The cover() method is supposed to replace the BingoSquare with a null, which will then be changed to "****" in the toString() method. I think I have all the code correct, but the cover() method is not covering any of the squares of myBingoCard with null. Help?

    Java Code:
    public class BingoCard
      private BingoSquare[][] myCard;
    //hard coding numbers into each row and column 
      public BingoCard()
        myCard = new BingoSquare[5][5];
        myCard[0][0] = new BingoSquare(3);
        myCard[0][1] = new BingoSquare(18);
        myCard[0][2] = new BingoSquare(33);
        myCard[0][3] = new BingoSquare(48);
        myCard[0][4] = new BingoSquare(63);
        myCard[1][0] = new BingoSquare(6);
        myCard[1][1] = new BingoSquare(21);
        myCard[1][2] = new BingoSquare(36);
        myCard[1][3] = new BingoSquare(51);
        myCard[1][4] = new BingoSquare(66);
        myCard[2][0] = new BingoSquare(9);
        myCard[2][1] = new BingoSquare(24);
        //myCard[2][2] = null;  moved down to toString()
        myCard[2][3] = new BingoSquare(54);
        myCard[2][4] = new BingoSquare(69);
        myCard[3][0] = new BingoSquare(12);
        myCard[3][1] = new BingoSquare(27);
        myCard[3][2] = new BingoSquare(42);
        myCard[3][3] = new BingoSquare(57);
        myCard[3][4] = new BingoSquare(72);
        myCard[4][0] = new BingoSquare(15);
        myCard[4][1] = new BingoSquare(30);
        myCard[4][2] = new BingoSquare(45);
        myCard[4][3] = new BingoSquare(60);
        myCard[4][4] = new BingoSquare(75);
      public String toString()
       myCard[2][2] = null;
       String a = ""; 
       for(int j = 0; j < 5; j++)
         for(int i = 0; i < 5; i++)
           //add a space somewhere in here below.
           if(myCard[j][i] != null){
           a += myCard[j][i] + " ";
           else a += "**** ";
         a += "\n";
       return a;
       public boolean cover(BingoBall ball){
        for(int row = 0; row < 5; row++){
          for(int col = 0; col < myCard[row].length; col++)
      if(myCard[row][col] != null && myCard[row][col].equals(ball.toString()))
        myCard[row][col] = null;
          return true;
        return false;
      public boolean hasBingo(){
       //four for loop for rows, columns, and two diagonals 
        for(int row = 0; row < myCard.length; row++){
          for(int col = 0; col < myCard[row].length; col++){
            if(myCard[row][col] == null){
             return true; 
        return false;
    ************************************************** *********************
    Java Code: code:
    //  Driver to test cover method in BingoCard class
    public class BingoGame
        Creates myBingoCard as a 5 x 5 array of BingoBalls
        Creates 5 specific BingoBalls and covers myBingocard
        Prints "Bingo" on a true return from cover method
        Prints final state of myBingoCard
      public static void main (String[] args)
        // create my Bingo Card
        BingoCard myBingoCard = new BingoCard();
        // create some Bingo Balls, cover on myBingoCard, and check for Bingo
        // change BingoBall values to test numbers on and not on your card
        // test at least one Bingo on a row, a column, or a diagonal
        if (myBingoCard.cover(new BingoBall(1)) && myBingoCard.hasBingo())  // not on myBingoCard
          System.out.println("Bingo on 1st");    
        if (myBingoCard.cover(new BingoBall(3)) && myBingoCard.hasBingo())  // next four are a diagonal
          System.out.println("Bingo on 2nd");
        if (myBingoCard.cover(new BingoBall(21)) && myBingoCard.hasBingo())
          System.out.println("Bingo on 3rd");
        if (myBingoCard.cover(new BingoBall(57)) && myBingoCard.hasBingo())
          System.out.println("Bingo on 4th");
        if (myBingoCard.cover(new BingoBall(75)) && myBingoCard.hasBingo())
          System.out.println("Bingo on 5th");
        // print the final state of myBingoCard
    Last edited by 08cmoss; 09-27-2012 at 04:18 AM.

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Eastern Florida
    Rep Power

    Default Re: Bingo cover() method not working. Help!

    my cover() method in BingoCard is not working.
    Please explain what "not working" means. The code has no comments describing what it is supposed to do.

    Please edit your post and wrap the code in code tags. See: BB Code List - Java Programming Forum
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. Replies: 4
    Last Post: 12-14-2011, 12:08 AM
  2. Bingo Null Pointer Exception
    By Bowsan22 in forum New To Java
    Replies: 4
    Last Post: 09-24-2011, 04:09 AM
  3. Multiplayer Bingo game
    By js4learn in forum Java Gaming
    Replies: 1
    Last Post: 07-08-2011, 03:43 AM
  4. Help please, bingo game.
    By XMarkoX in forum New To Java
    Replies: 8
    Last Post: 11-23-2009, 09:45 AM
  5. Multi Client-Bingo
    By Aga^^ in forum Networking
    Replies: 0
    Last Post: 05-23-2009, 05:21 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts