Menu

[solved]-Code Without Array Domain Public Class Bingo Param Args Command Line Arguments Public Stat Q39023260

Re-do the BINGO game from Module 5, but this time use a 2-D array of 5 rows with 5 columns to representa Bingo Card (instead

This is my code without an array

Domain

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
Scanner sc = new Scanner(System.in);
int choice;
do{
gameCard = new BingoCard();
playGame(); //variables
determineWinner(); //variables
System.out.print(“Do you want to play again?(1 = Yes|2 = No)”);//ask user yes or no
choice = sc.nextInt();
}
while(choice==1); // if true will play
  
}
  
public static void playGame()
{
Random rand = new Random();
for(int i=1;i<=25;i++){
int value = rand.nextInt(75)+1;
if(1<=value && value<=15)
{
if(gameCard.getbNum1()== value)
gameCard.setbNum1(0);

else if(gameCard.getbNum2()== value)
gameCard.setbNum2(0);
  
else if(gameCard.getbNum3()== value)
gameCard.setbNum3(0);

else if(gameCard.getbNum4()== value)
gameCard.setbNum4(0);

else if(gameCard.getbNum5()== value)
gameCard.setbNum5(0);
}

//Loop 25 times, simulating the 25 balls in a BINGO game
//Inside loop:
//1. Generate a random number between 1 and 75
  
else if(16<=value && value<=30)
{
if(gameCard.getiNum1()==value)
gameCard.setiNum1(0);
else if(gameCard.getiNum2()==value)
gameCard.setiNum2(0);
else if(gameCard.getiNum3()==value)
gameCard.setiNum3(0);
else if(gameCard.getiNum4()==value)
gameCard.setiNum4(0);
else if(gameCard.getiNum5()==value)
gameCard.setiNum5(0);
}
  
//2. if the number generated is between 1–15,
// check bNum1, bNum2, bNum3, bNum4, and bNum5 to see if there is amatch;
// if so, move a 0 to the matching instance variable in thegameCard
  
  
else if(31<=value && value<=45)
{
if(gameCard.getnNum1()==value)
gameCard.setnNum1(0);
else if(gameCard.getnNum2()==value)
gameCard.setnNum2(0);
else if(gameCard.getnNum3()==value)
gameCard.setnNum3(0);
else if(gameCard.getnNum4()==value)
gameCard.setnNum4(0);
else if(gameCard.getnNum5()==value)
gameCard.setnNum5(0);
}   
//3. if the number generated is between 16–30,
// check iNum1, iNum2, iNum3, iNum4, and iNum5 to see if there is amatch;
// if so, move a 0 to the matching instance variable in thegameCard
  
  
else if(46<=value && value<=60)
{
if(gameCard.getgNum1()==value)
gameCard.setgNum1(0);
else if(gameCard.getgNum2()==value)
gameCard.setgNum2(0);
else if(gameCard.getgNum3()==value)
gameCard.setgNum3(0);
else if(gameCard.getgNum4()==value)
gameCard.setgNum4(0);
else if(gameCard.getgNum5()==value)
gameCard.setgNum5(0);
}   
//4. if the number generated is between 31–45,
// check nNum1, nNum2, nNum3, nNum4, and nNum5 to see if there is amatch;
// if so, move a 0 to the matching instance variable in thegameCard
  
  
//5. if the number generated is between 46–60,
// check gNum1, gNum2, gNum3, gNum4, and gNum5 to see if there is amatch;
// if so, move a 0 to the matching instance variable in thegameCard
else if(61<=value && value<=75)
{
if(gameCard.getoNum1()==value)
gameCard.setoNum1(0);
else if(gameCard.getoNum2()==value)
gameCard.setoNum2(0);
else if(gameCard.getoNum3()==value)
gameCard.setoNum3(0);
else if(gameCard.getoNum4()==value)
gameCard.setoNum4(0);
else if(gameCard.getoNum5()==value)
gameCard.setoNum5(0);
//6. if the number generated is between 61–75,
// check oNum1, oNum2, oNum3, oNum4, and oNum5 to see if there is amatch;
// if so, move a 0 to the matching instance variable in thegameCard
  
}
}
}
public static void determineWinner()
{
//1. Print the content of the Bingo Card, ensuring the display isformatted 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
System.out.println(gameCard.getbNum1()+” “+gameCard.getiNum1()+””+gameCard.getnNum1()+” “+gameCard.getgNum1()+””+gameCard.getoNum1()); //prints out the game card
System.out.println(gameCard.getbNum2()+” “+gameCard.getiNum2()+””+gameCard.getnNum2()+” “+gameCard.getgNum2()+””+gameCard.getoNum2()); //prints out the game card
System.out.println(gameCard.getbNum3()+” “+gameCard.getiNum3()+””+gameCard.getnNum3()+” “+gameCard.getgNum3()+””+gameCard.getoNum3()); //prints out the game card
System.out.println(gameCard.getbNum4()+” “+gameCard.getiNum4()+””+gameCard.getnNum4()+” “+gameCard.getgNum4()+””+gameCard.getoNum4()); //prints out the game card
System.out.println(gameCard.getbNum5()+” “+gameCard.getiNum5()+””+gameCard.getnNum5()+” “+gameCard.getgNum5()+””+gameCard.getoNum5()); //prints out the game card
  
//2. Call the gotBingo() method for the gameCard
if(gameCard.gotBingo())
{
totalGamesWon++;
System.out.println(“BINGO!”);
}
//3. if gotBingo() returns true, add 1 to totalGamesWon
// AND display “BINGO!”
else
{
System.out.println(“No BINGO”);
}
//4. if gotBingo() returns false, display “No BINGO”
}
  
}

DRIVE

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 BingoCard, using
//the following range of numbers:
  
// “B” (numbers 1–15), “I” (numbers 16–30),
// “N” (numbers 31–45), “G” (numbers 46–60),
// and “O” (numbers 61–75).
Random myRan = new Random();

bNum1 = myRan.nextInt(15) + 1;

bNum2 = myRan.nextInt(15) + 1;

bNum3 = myRan.nextInt(15) + 1;

bNum4 = myRan.nextInt(15) + 1;

bNum5 = myRan.nextInt(15) + 1;

  

iNum1 = myRan.nextInt(15) + 16;

iNum2 = myRan.nextInt(15) + 16;

iNum3 = myRan.nextInt(15) + 16;

iNum4 = myRan.nextInt(15) + 16;

iNum5 = myRan.nextInt(15) + 16;

  

nNum1 = myRan.nextInt(15) + 31;

nNum2 = myRan.nextInt(15) + 31;

nNum3 = myRan.nextInt(15) + 31;

nNum4 = myRan.nextInt(15) + 31;

nNum5 = myRan.nextInt(15) + 31;

  

gNum1 = myRan.nextInt(15) + 46;

gNum2 = myRan.nextInt(15) + 46;

gNum3 = myRan.nextInt(15) + 46;

gNum4 = myRan.nextInt(15) + 46;

gNum5 = myRan.nextInt(15) + 46;

  

oNum1 = myRan.nextInt(15) + 61;

oNum2 = myRan.nextInt(15) + 61;

oNum3 = myRan.nextInt(15) + 61;

oNum4 = myRan.nextInt(15) + 61;

oNum5 = myRan.nextInt(15) + 61;
}

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 boolean gotBingo()
{
  
  
if(bNum1+bNum2+bNum3+bNum4+bNum5==0)
{
return true;
}
  

else if(iNum1+iNum2+iNum3+iNum4+iNum5==0)
{
return true;
}

else if(nNum1+nNum2+nNum3+nNum4+nNum5==0)
{
return true;   
}
  

else if(gNum1+gNum2+gNum3+gNum4+gNum5==0)
{
return true;
}

else if(oNum1+oNum2+oNum3+oNum4+oNum5==0)
{
return true;
}

else if(bNum1+iNum1+nNum1+gNum1+oNum1==0)
{
return true;
}

else if(bNum2+iNum2+nNum2+gNum2+oNum2==0)
{
return true;
}
  

else if(bNum3+iNum3+nNum3+gNum3+oNum3==0)
{
return true;
}

else if(bNum4+iNum4+nNum4+gNum4+oNum4==0)
{
return true;
}

else if(bNum5+iNum5+nNum5+gNum5+oNum5==0)
{
return true;
}

else if(bNum1+iNum2+nNum3+gNum4+oNum5==0)
{
return true;
}

else if(bNum5+iNum4+nNum3+gNum2+oNum1==0)
{
return true;   
}
  

  
  
return false;
}

public boolean Vertical()

{

return false;

}
}

Re-do the BINGO game from Module 5, but this time use a 2-D array of 5 rows with 5 columns to representa Bingo Card (instead of 25 variables). Make the needed changes to the BingoCard domain class, and the Bingo driver class. Good luck! Rubric for 2-D array version of BINGO Game Criteria Ratings Pts Comments at beginning of each class, and before each method. 20.0 pts grid.column 1.label 10.0 pts grid.column2.label 0.0 pts grid.column3.label 20.0 pts In the domain class, BingoCard, complete the constructor to generate 25 random numbers, with specific number ranges for B, I, N, G, and o in a 2-D array. 15.0 pts grid.column2.label 0.0 pts grid.column3.label grid.column 1.label 30.0 pts In the domain class, BingoCard, code the gotBingo() method, which will check if there was horizontal, vertical, or diagonal BINGO in a 2-D array. 30.0 pts grid.column 1.label 15.0 pts grid.column2.label 0.0 pts grid.column3.label 30.0 pts 40.0 pts grid.column 1.label 20.0 pts grid.column2.label 0.0 pts grid.column3.label In the driver class, Bingo, code the main method, which will 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. 40.0 pts 40.0 pts grid.column 1.label 20.0 pts grid.column2.label 0.0 pts grid.column3.label In driver class, Bingo, code the playGame method, which loops 25 times to generate a random number between 1 and 75, check if there is a match on the BingoCard 2-D array, and move a 0 to the location in the 2-D array where there is a match. 40.0 pts 40.0 pts grid.column 1.label 20.0 pts grid.column2.label 0.0 pts grid.column3.label In driver class, Bingo, code the determineWinner() method, which displays the BingoCard, calls the gotBingo() method of the BingoCard object, and displays either “BINGO!” or “No Bingo.” If “BINGO” then add 1 to totalGamesWon. 40.0 pts 25 points Extra Credit: Check for duplicates in constructor of Bingo Card 0.0 pts grid.column 1.label 0.0 pts grid.column2.label 0.0 pts grid.column3.label 0.0 pts Total Points: 200.0 Show transcribed image text Re-do the BINGO game from Module 5, but this time use a 2-D array of 5 rows with 5 columns to representa Bingo Card (instead of 25 variables). Make the needed changes to the BingoCard domain class, and the Bingo driver class. Good luck! Rubric for 2-D array version of BINGO Game Criteria Ratings Pts Comments at beginning of each class, and before each method. 20.0 pts grid.column 1.label 10.0 pts grid.column2.label 0.0 pts grid.column3.label 20.0 pts In the domain class, BingoCard, complete the constructor to generate 25 random numbers, with specific number ranges for B, I, N, G, and o in a 2-D array. 15.0 pts grid.column2.label 0.0 pts grid.column3.label grid.column 1.label 30.0 pts In the domain class, BingoCard, code the gotBingo() method, which will check if there was horizontal, vertical, or diagonal BINGO in a 2-D array. 30.0 pts grid.column 1.label 15.0 pts grid.column2.label 0.0 pts grid.column3.label 30.0 pts 40.0 pts grid.column 1.label 20.0 pts grid.column2.label 0.0 pts grid.column3.label In the driver class, Bingo, code the main method, which will 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. 40.0 pts 40.0 pts grid.column 1.label 20.0 pts grid.column2.label 0.0 pts grid.column3.label In driver class, Bingo, code the playGame method, which loops 25 times to generate a random number between 1 and 75, check if there is a match on the BingoCard 2-D array, and move a 0 to the location in the 2-D array where there is a match. 40.0 pts 40.0 pts grid.column 1.label 20.0 pts grid.column2.label 0.0 pts grid.column3.label In driver class, Bingo, code the determineWinner() method, which displays the BingoCard, calls the gotBingo() method of the BingoCard object, and displays either “BINGO!” or “No Bingo.” If “BINGO” then add 1 to totalGamesWon. 40.0 pts 25 points Extra Credit: Check for duplicates in constructor of Bingo Card 0.0 pts grid.column 1.label 0.0 pts grid.column2.label 0.0 pts grid.column3.label 0.0 pts Total Points: 200.0

Expert Answer


Answer to This is my code without an array Domain public class Bingo { /** * @param args the command line arguments */ public stat… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *