Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

his is a simulation of a simplified BINGO game. It consists of 2 classes: Bingo (driver) and BingoCard (domain). There will be coding needed for

image text in transcribed

his is a simulation of a simplified BINGO game. It consists of 2 classes: Bingo (driver) and BingoCard (domain). There will be coding needed for both classes. Use the attached skeleton of both classes, following the comments provided within the skeleton code. In the BingoCard class: 1.) Complete the constructor that generates 25 numbers in a Bingo card 2.) Complete the gotBingo() method, which checks if there is vertical, horizontal, or diagonal Bingo 3.) Create a toString() method in the BingoCard class that will print the contents like an actual Bingo card. B I N G O 15 17 32 47 65

In the Bingo class: 1.) Complete the main method to do the following: Use do-while loop to do the following: 1. instantiate a gameCard object 2. call the method playGame() 3. call the method determineWinner() 4. ask user if they wish to play again? (1 = yes; 2 = no) 5. loop while user replies 1 6. display value in totalGamesWon 2.) Complete the playGame() method, simulating the drawing of 25 Bingo balls in the range of 1 to 75, and filling in the gameCard object with 0's when there is a match

3.) Complete the determineWinner() method, which displays the gameCard object, checks if there was vertical, horizontal, or diagonal BINGO, and keeps track of the number of games won..

Code

/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package bingo;

/** * * @author cristy */ public class Bingo {

/** * @param args the command line arguments */ public static BingoCard gameCard; public static int totalGamesWon = 0; public static void main(String[] args) { //Use do-while loop to do the following: //1. instantiate a gameCard //2. call the method playGame() //3. call the method determineWinner() //4. Ask user if they wish to play again? (1 = yes; 2 = no) //5. Loop while user replies 1 //Display value in totalGamesWon } public static void playGame() { //Loop 25 times, simulating the 25 balls in a BINGO game //Inside loop: //1. Generate a random number between 1 and 75 //2. if the number generated is between 115, // check bNum1, bNum2, bNum3, bNum4, and bNum5 to see if there is a match; // if so, move a 0 to the matching instance variable in the gameCard //3. if the number generated is between 1630, // check iNum1, iNum2, iNum3, iNum4, and iNum5 to see if there is a match; // if so, move a 0 to the matching instance variable in the gameCard //4. if the number generated is between 3145, // check nNum1, nNum2, nNum3, nNum4, and nNum5 to see if there is a match; // if so, move a 0 to the matching instance variable in the gameCard //5. if the number generated is between 4660, // check gNum1, gNum2, gNum3, gNum4, and gNum5 to see if there is a match; // if so, move a 0 to the matching instance variable in the gameCard //6. if the number generated is between 6175, // check oNum1, oNum2, oNum3, oNum4, and oNum5 to see if there is a match; // if so, move a 0 to the matching instance variable in the gameCard } public static void determineWinner() { //1. Print the content of the Bingo Card, ensuring the display is formatted as follows: // bNum1 iNum1 nNum1 gNum1 oNum1 // bNum2 iNum2 nNum2 gNum2 oNum2 // bNum3 iNum3 nNum3 gNum3 oNum3 // bNum4 iNum4 nNum4 gNum4 oNum4 // bNum5 iNum5 nNum5 gNum5 oNum5 //2. Call the gotBingo() method for the gameCard //3. if gotBingo() returns true, add 1 to totalGamesWon // AND display "BINGO!" //4. if gotBingo() returns false, display "No BINGO" } }

/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package bingo;

/** * * @author cristy */ public class BingoCard { //These ints are initialized to random numbers between private int bNum1; private int bNum2; private int bNum3; private int bNum4; private int bNum5; private int iNum1; private int iNum2; private int iNum3; private int iNum4; private int iNum5; private int nNum1; private int nNum2; private int nNum3; private int nNum4; private int nNum5; private int gNum1; private int gNum2; private int gNum3; private int gNum4; private int gNum5; private int oNum1; private int oNum2; private int oNum3; private int oNum4; private int oNum5; public BingoCard() { //Constructor for a BingoCard //Generate a random number for each instance variable in the Bingo Card, using //the following range of numbers: // "B" (numbers 115), "I" (numbers 1630), // "N" (numbers 3145), "G" (numbers 4660), // and "O" (numbers 6175). }

public int getbNum1() { return bNum1; }

public int getbNum2() { return bNum2; }

public int getbNum3() { return bNum3; }

public int getbNum4() { return bNum4; }

public int getbNum5() { return bNum5; }

public int getiNum1() { return iNum1; }

public int getiNum2() { return iNum2; }

public int getiNum3() { return iNum3; }

public int getiNum4() { return iNum4; }

public int getiNum5() { return iNum5; }

public int getnNum1() { return nNum1; }

public int getnNum2() { return nNum2; }

public int getnNum3() { return nNum3; }

public int getnNum4() { return nNum4; }

public int getnNum5() { return nNum5; }

public int getgNum1() { return gNum1; }

public int getgNum2() { return gNum2; }

public int getgNum3() { return gNum3; }

public int getgNum4() { return gNum4; }

public int getgNum5() { return gNum5; }

public int getoNum1() { return oNum1; }

public int getoNum2() { return oNum2; }

public int getoNum3() { return oNum3; }

public int getoNum4() { return oNum4; }

public int getoNum5() { return oNum5; }

public void setbNum1(int bNum1) { this.bNum1 = bNum1; }

public void setbNum2(int bNum2) { this.bNum2 = bNum2; }

public void setbNum3(int bNum3) { this.bNum3 = bNum3; }

public void setbNum4(int bNum4) { this.bNum4 = bNum4; }

public void setbNum5(int bNum5) { this.bNum5 = bNum5; }

public void setiNum1(int iNum1) { this.iNum1 = iNum1; }

public void setiNum2(int iNum2) { this.iNum2 = iNum2; }

public void setiNum3(int iNum3) { this.iNum3 = iNum3; }

public void setiNum4(int iNum4) { this.iNum4 = iNum4; }

public void setiNum5(int iNum5) { this.iNum5 = iNum5; }

public void setnNum1(int nNum1) { this.nNum1 = nNum1; }

public void setnNum2(int nNum2) { this.nNum2 = nNum2; }

public void setnNum3(int nNum3) { this.nNum3 = nNum3; }

public void setnNum4(int nNum4) { this.nNum4 = nNum4; }

public void setnNum5(int nNum5) { this.nNum5 = nNum5; }

public void setgNum1(int gNum1) { this.gNum1 = gNum1; }

public void setgNum2(int gNum2) { this.gNum2 = gNum2; }

public void setgNum3(int gNum3) { this.gNum3 = gNum3; }

public void setgNum4(int gNum4) { this.gNum4 = gNum4; }

public void setgNum5(int gNum5) { this.gNum5 = gNum5; }

public void setoNum1(int oNum1) { this.oNum1 = oNum1; }

public void setoNum2(int oNum2) { this.oNum2 = oNum2; }

public void setoNum3(int oNum3) { this.oNum3 = oNum3; }

public void setoNum4(int oNum4) { this.oNum4 = oNum4; }

public void setoNum5(int oNum5) { this.oNum5 = oNum5; } public boolean gotBingo() { //when a game is being played, if the letter and number match //the letter and number called out, its value will be zeroed out //to simulate placing a button on that location. //to determine if the card has BINGO, one of the following conditions must be true: //1. Vertical: bNum1, bNum2, bNum3, bNum4, and bNum5 must all be 0's OR // iNum1, iNum2, iNum3, iNum4, and iNum5 must all be 0's OR // nNum1, nNum2, nNum3, nNum4, and nNum5 must all be 0's OR // gNum1, gNum2, gNum3, gNum4, and gNum5 must all be 0's OR // oNum1, oNum2, oNum3, oNum4, and oNum5 must all be 0's //2. Horizontal: bNum1, iNum1, nNum1, gNum1, and oNum1 must all be 0's OR // bNum2, iNum2, nNum2, gNum2, and oNum2 must all be 0's OR // bNum3, iNum3, nNum3, gNum3, and oNum3 must all be 0's OR // bNum4, iNum4, nNum4, gNum4, and oNum4 must all be 0's OR // bNum5, iNum5, nNum5, gNum5, and oNum5 must all be 0's //3. Diagonal: bNum1, iNum2, nNum3, gNum4, and oNum5 must all be 0's OR // bNum5, iNum4, nNum3, gNum2, and oNum1 must all be 0's //When any of the above 12 conditions are true, return true. Otherwise, return false; return false; } }

BINGO for COP2250-A Visualization The gotBingo() method in the Bingo (Driver) class will return TRUE if 5 numbers were set to 0 either horizontally, vertically, or diagonally. Otherwise, the method will return FALSE. Each vertical check is a set of if-else if statements A separate set of if-else if statements will be found for each horizontal check Each diagonal check is a set of if-else if statements When gotBingo()ends, it will have either returned a TRUE or a FALSE 81=7 The constructor of the BingoCard class will generate random numbers to fill in all of these 25 instance variables. These 25 numbers represent 1 card with BINGO columns. Thus, card 1 consists of 5 columns (BI N G O, where each column contains 5 rows (example, the B column has the 5 rows: B1, B2, B3, B4, B5). 83 4 B4 = 3 85= 14 The totalGamsWon is a global variable for keeping track of how many games the user wins instead of the computer. Before the l3=25 4-19 IS = 27 N1 = 34 N2 38 N3 40 The determineWinner) method in the Bingo (Driver) class will call the gotBingol) method, and If it returns true, it will add 1 to the totalGamesWon, otherwise it will leave the totalGamesWon alone. The toStcine) method of the BingoCard will display the content of the entire BINGO card as follows Finally, the main method will contain a do-while loop that will execute at least once, and do the following NS = 42 G2 53 1 1 Ni G1 01 B2 12 N2 62 02 B3 13 N3 G3 03 B4 14 N4 G4 04 BS IS NS GS OS 1.) Instantiate the gRcar class imto an object 2.) Call the playGame) method in the driver class 3.) Call the detomingWinngn) method, which calls the g9tBingel) method, and add 1 to G4 55 totalGamesWom whenever gotBingo returns true. 4.) Ask user if he/she wants to repeat and play BINGO again. 01 = 63 02 68 03 = 70 04 72 The playGame) method in the Bingo (Driver) class will loop to generate 25 random numbers in the range of 1 to 75. This simulates drawing 25 numbers in a BINGO game. The method will check if the number generated randomly is in the B range (1-15), I range (16-30), N range (31-45), G range (46 .60) and O range (61-75). Whichever range it is in, the method will check each of the S variables in that range, to see if the number randomly generated is in any of the 5 varlables in that range. Example: randomNum 27 was randomly generated, which belongs to the range of variables(1s-30 range): inum1-0; (andPMNum) else if (Inum2 inum2 0; I/the 0 being moved to the number simulates putting a chip on the Bingo card, marking that the // number was called. etc. BINGO for COP2250-A Visualization The gotBingo() method in the Bingo (Driver) class will return TRUE if 5 numbers were set to 0 either horizontally, vertically, or diagonally. Otherwise, the method will return FALSE. Each vertical check is a set of if-else if statements A separate set of if-else if statements will be found for each horizontal check Each diagonal check is a set of if-else if statements When gotBingo()ends, it will have either returned a TRUE or a FALSE 81=7 The constructor of the BingoCard class will generate random numbers to fill in all of these 25 instance variables. These 25 numbers represent 1 card with BINGO columns. Thus, card 1 consists of 5 columns (BI N G O, where each column contains 5 rows (example, the B column has the 5 rows: B1, B2, B3, B4, B5). 83 4 B4 = 3 85= 14 The totalGamsWon is a global variable for keeping track of how many games the user wins instead of the computer. Before the l3=25 4-19 IS = 27 N1 = 34 N2 38 N3 40 The determineWinner) method in the Bingo (Driver) class will call the gotBingol) method, and If it returns true, it will add 1 to the totalGamesWon, otherwise it will leave the totalGamesWon alone. The toStcine) method of the BingoCard will display the content of the entire BINGO card as follows Finally, the main method will contain a do-while loop that will execute at least once, and do the following NS = 42 G2 53 1 1 Ni G1 01 B2 12 N2 62 02 B3 13 N3 G3 03 B4 14 N4 G4 04 BS IS NS GS OS 1.) Instantiate the gRcar class imto an object 2.) Call the playGame) method in the driver class 3.) Call the detomingWinngn) method, which calls the g9tBingel) method, and add 1 to G4 55 totalGamesWom whenever gotBingo returns true. 4.) Ask user if he/she wants to repeat and play BINGO again. 01 = 63 02 68 03 = 70 04 72 The playGame) method in the Bingo (Driver) class will loop to generate 25 random numbers in the range of 1 to 75. This simulates drawing 25 numbers in a BINGO game. The method will check if the number generated randomly is in the B range (1-15), I range (16-30), N range (31-45), G range (46 .60) and O range (61-75). Whichever range it is in, the method will check each of the S variables in that range, to see if the number randomly generated is in any of the 5 varlables in that range. Example: randomNum 27 was randomly generated, which belongs to the range of variables(1s-30 range): inum1-0; (andPMNum) else if (Inum2 inum2 0; I/the 0 being moved to the number simulates putting a chip on the Bingo card, marking that the // number was called. etc

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions