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

I have final project on computer class. This is my code for Bingo game but I hav

ID: 3583116 • Letter: I

Question

I have final project on computer class. This is my code for Bingo game but I have problem on it

import java.util.*;

import java.awt.*;

import javax.swing.*;

import java.awt.event.*;

import java.util.ArrayList;

import java.util.Scanner;

import java.util.HashMap;

import java.util.Random;

public class BingoGame extends JFrame

{

  

JPanel CardPanel;

JLabel BCell1;

JLabel ICell1;

public BingoGame()

{

buildBingoCardPanel();

  

add(CardPanel);

setSize(500,500);

setVisible(true);

}

public void buildBingoCardPanel()

{

CardPanel = new JPanel();

BCell1 = new JLabel("");

ICell1 = new JLabel("");

fillCells();

CardPanel.add(BCell1);

CardPanel.add(ICell1);

  

}

public void fillCells()

{

int randNum = (int)(Math.random()*15) + 1;

BCell1.setText(String.valueOf(randNum));

  

Random myRandom = new Random(15);

randNum = myRandom.nextInt();

BCell1.setText(String.valueOf(randNum));

  

  

ArrayList<Integer> Bnumbers = new ArrayList<Integer>();

for (int i=1; i<=15; i++)

{

Bnumbers.add(i);

  

}

Collections.shuffle(Bnumbers);

System.out.println(Bnumbers);

  

  

  

BCell1.setText((Bnumbers.get(0)).toString());

  

}

public static void main(String[] args)

{

BingoGame myGame = new BingoGame();

}

}

class BingoBoard

{

private String board[][];

private final int BOARD_DIM = 5;

private final int MAX_SIZE = BOARD_DIM * BOARD_DIM;

private HashMap<String,Boolean> eventCalledMap;

private ArrayList<String> events;

private ArrayList<String> selectedEvents;

private final String FREE = "FREE SPACE";

private final int player;

private boolean win;

BingoBoard()

{

board = new String[BOARD_DIM][BOARD_DIM];

selectedEvents = new ArrayList<>();

events = new ArrayList<>();

eventCalledMap = new HashMap<>();

eventCalledMap.put(FREE, true);

player = -1;

win = false;

}//end BingoBoard

BingoBoard(ArrayList<String> eventList)

{

board = new String[BOARD_DIM][BOARD_DIM];

selectedEvents = new ArrayList<>();

events = eventList;

eventCalledMap = new HashMap<>();

eventCalledMap.put(FREE, true);

player = -1;

win = false;

}//end BingoBoard

BingoBoard(ArrayList<String> eventList, int numb)

{

board = new String[BOARD_DIM][BOARD_DIM];

selectedEvents = new ArrayList<>();

events = eventList;

eventCalledMap = new HashMap<>();

eventCalledMap.put(FREE, true);

player = numb;

win = false;

}

public void updateEvents(ArrayList<String> eventList)

{

events.addAll(eventList);

}

public boolean randomizeEvents()

{

if(this.events.size() < MAX_SIZE - 1)

return false;

while(selectedEvents.size() < MAX_SIZE - 1)

{

Random rand = new Random();

int index = rand.nextInt(this.events.size());

String str = events.get(index);

selectedEvents.add(str);

events.remove(str);

}

int count = 0;

for(String str:selectedEvents)

{

eventCalledMap.put(str,false);

if(count == MAX_SIZE/2)

{

board[count/BOARD_DIM][count%BOARD_DIM] = FREE;

count++;

}

board[count/BOARD_DIM][count%BOARD_DIM] = str;

count++;

}

return true;

}

public void printBoard()

{

System.out.printf("Player %d ",this.player);

System.out.println("_____________________");

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

{

System.out.println("|---|---|---|---|---|");

for(int j = 0; j < BOARD_DIM; j++)

if(eventCalledMap.get(board[i][j]) == true)

System.out.printf("|%3s", "X");

else

System.out.printf("|%3s",board[i][j]);

System.out.println("|");

}

System.out.println("|---|---|---|---|---|");

System.out.println("_____________________ ");

}

public void putMarker(String value)

{

if(eventCalledMap.containsKey(value))

eventCalledMap.put(value, Boolean.TRUE);

}

public boolean checkWin()

{

this.win = evalBoard();

return this.win;

}

public boolean won()

{

return this.win;

}

public int getPlayer()

{

return player;

}

private boolean evalBoard()

{

int i, j, count;

for(i = 0; i < BOARD_DIM; i++)

{

j = 0;

count = 0;

  

while(eventCalledMap.get(board[i][j]) != false)

{

count++;

j++;

if(count == BOARD_DIM)

return true;

}//end while

j = 0;

count = 0;

while(eventCalledMap.get(board[j][i]) != false)

{

count++;

j++;

if(count == BOARD_DIM)

return true;

}

}

i = 0;

count = 0;

while(eventCalledMap.get(board[i][i]) != false)

{

count++;

i++;

if(count == BOARD_DIM)

return true;

}//end while

i = BOARD_DIM -1;

j = 0;

count = 0;

while(eventCalledMap.get(board[i][j]) != false)

{

count++;

i--;

j++;

if(count == BOARD_DIM)

return true;

}

return false;

}

}

public class BingoGame

{

private ArrayList<String> eventList;

private final int DEFAULT_PLAYER_COUNT = 2;

private int playerCount;

private boolean winnerDetermined;

private ArrayList<BingoBoard> boardList;

BingoGame()

{

this.eventList = new ArrayList<>();

this.playerCount = DEFAULT_PLAYER_COUNT;

this.winnerDetermined = false;

this.boardList = new ArrayList<>();

}

BingoGame(int players)

{

this.eventList = new ArrayList<>();

this.playerCount = players;

this.winnerDetermined = false;

boardList = new ArrayList<>();

}

public void addEvent(String event)

{

this.eventList.add(event);

}

public void startGame()

{

this.winnerDetermined = false;

for(int i = 1; i <= this.playerCount;i++)

{

ArrayList<String> events = (ArrayList<String>) eventList.clone();

BingoBoard board = new BingoBoard(events,i);

board.randomizeEvents();

this.boardList.add(board);

board.printBoard();

}

Scanner in = new Scanner(System.in);

while(this.winnerDetermined == false)

{

System.out.println("Enter Event:");

String check = in.next();

for(BingoBoard boards:boardList)

{

boards.putMarker(check);

boards.printBoard();

if(winnerDetermined == false)

winnerDetermined = boards.checkWin();

else

boards.checkWin();

}

}

this.printWinner();

}

private void printWinner()

{

for(BingoBoard boards:boardList)

{

if(boards.won())

System.out.printf("Player %d wins! ",boards.getPlayer());

}

}

public static void main(String[] args)

{

BingoGame game = new BingoGame(4);

for(int i=1; i<=25; i++)

game.addEvent(Integer.toString(i));

game.startGame();

}

}

here is grading for Bingogame

45 pts: Bingo Board with RANDOM numbers

5 pts: CORRECT random numbers on board and NO duplicates:

            B: 1-15, I:16-30, N:31-45, G:46-60, O:61-75

5 pts: Button or other way to control game … “Next Bingo Ball Number”

5 pts: Random number generated for “next bingo ball” – NO duplicates

5 pts: Select Bingo number called on board (by you or the computer)

5 pts: NEW game feature to start over after win or in middle of game

20 pts: Check if user wins (horizontally, vertically, or diagonally)

Explanation / Answer

}

//CORRECT random numbers on board and NO duplicates:

            B: 1-15, I:16-30, N:31-45, G:46-60, O:61-75

import java.util.*;

import java.io.*;

public class Bingogame

{

        private Random rand = new Random();

        private int[][] card;       //Bingogame card configuration

        private int[] stream;       //list of 75 integers

        private boolean[][] marks; //simulates placing chips on a Bingogame card

        public Bingogame()

        {

               card   = new int[5][5];

               stream = new int[75];

               marks = new boolean[5][5];

        }

        public void write(String outputFile) throws IOException

        {

               throw new RuntimeException ("You need to implement this methods");

        }

/**

   * Shufflings the list of numbers

   */

   public void shuffling(ArrayList<Integer> list)

   {

              

               throw new RuntimeException ("You need to implement this methods");

   }

   public void read(String inputFile) throws IOException

   {

               throw new RuntimeException ("You need to implement this methods");

        }

   public int playGame()

   {

               throw new RuntimeException ("You need to implement this methods");

        }

}

/**

* Check if user wins (horizontally, vertically, or diagonally)

* @return true if a win is found

*/

private boolean evalBoard1() {

    for (int i = 0; i < BOARD_DIM; i++) {

        // Checks horizontally for a win.

        if (evalLine1(0, i, 1, 0)) {

            return true;

        }

        // Checks vertically for a win.

        if (evalLine1(i, 0, 0, 1)) {

            return true;

        }

    }

    // Checks the top left to bottom right diagonal for a win.

    if (evalLine1(0, 0, 1, 1)) {

        return true;

    }

    // Checks the top right to bottom left diagonal for a win.

    if (evalLine1(BOARD_DIM-1, 0, -1, 1)) {

        return true;

    }

    return false;

}

private boolean evalLine1(int startxx, int startyy, int deltaxx, int deltayy) {

    int counting = 0;

    int x = startxx;

    int y = startyy;

    while (!eventCalledMap.get(board[x][y])) {

        x += deltaxx;

        y += deltayy;

        if (++counting == BOARD_DIM) {

            return true;

        }

    }

    return false;

}