Question: This is the code i have written this so far ... but i need it all to fall under one class and to fulfill all

This is the code i have written this so far ... buti need it all to fall under one class and to fulfillThis is the code i have written this so far ... but i need it all to fall under one class and to fulfill all the the test cases ( i have included the test code.) Please help edit my code so that it works as required. Thank you

MY CODE

import java.util.Random;

public class Main {

public static void main(String[] args) {

int[][] number1 = { { 10, 30, 45, 66, 82 }, { 3, 25, 11, 63, 78 }, { 22, 4, 13, 46, 90 } };

Card[] cards1 = new Card[1];

cards1[0] = new Card(number1);

int[][] number2 = { { 19, 53, 61, 32, 6 }, { 11, 44, 56, 73, 81 }, { 78, 31, 69, 9, 23 } };

Card[] cards2 = new Card[1];

cards2[0] = new Card(number2);

Player[] players = new Player[2];

players[0] = new Player("Player1", cards1);

players[1] = new Player("Player2", cards2);

Bingo bingo = new Bingo(players);

Random random = new Random();

String winner = "";

while (winner.equals("")) {

int number = random.nextInt(90) + 1;

winner = bingo.play(number);

}

System.out.println(winner);

}

}

public class bingo {

private Player[] players;

public bingo(Player[] player) {

this.players = player;

}

public String play(int number) {

for (int i = 0; i

players[i].markNumber(number);

}

String winners = "";

for (int i = 0; i

if (players[i].isWinner())

winners += players[i].getName() + " ";

}

return winners;

}

}

public class Card {

private int[][] number;

private boolean[][] marks = new boolean[3][5];

public Card(int[][] number) {

this.number = number;

}

public int getNumber(int row, int column) {

return number[row - 1][column - 1];

}

public boolean isMarked(int row, int column) {

return marks[row - 1][column - 1];

}

public void markNumber(int number) {

for (int i = 0; i

for (int j = 0; j

if (this.number[i][j] == number) {

this.marks[i][j] = true;

}

}

}

}

}

public class Player {

private String name;

private Card[] cards;

public Player(String name, Card[] cards) {

this.name = name;

this.cards = cards;

}

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public Card[] getCard() {

return cards;

}

public void setCard(Card[] card) {

this.cards = card;

}

public boolean isWinner() {

boolean flag = true;

for (int i = 0; i

for (int j = 0; j

for (int k = 0; k

flag = flag && cards[i].isMarked(j + 1, k + 1);

}

if (flag == true) {

return true;

}

}

}

return false;

}

public void markNumber(int number) {

for (int i = 0; i

cards[i].markNumber(number);

}

}

}

TEST CODE

import java.util.Scanner;

public class BingoTest {

// Test 1 // Should say "Player0 Player1" at the bottom private static String test1 = "2 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 5 1 2 3 4 5";

// Test 2 // Should say "Player0" at the bottom private static String test2 = "2 1 10 30 45 66 82 3 25 11 63 78 22 4 13 46 90 5 23 12 6 85 1 88 67 2 44 1 11 31 46 67 83 4 26 12 64 79 23 5 14 47 90 6 24 13 7 86 2 89 68 3 45 9 10 11 30 46 45 66 47 90 82";

// Test 3 // Should say "Player2 Player3" at the bottom private static String test3 = "4 1 10 30 45 66 82 3 25 11 63 78 22 4 13 46 90 5 23 12 6 85 1 88 67 2 44 1 11 31 46 67 83 4 26 12 64 79 23 5 14 47 90 6 24 13 7 86 2 89 68 3 45 1 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 1 2 4 6 8 10 12 14 16 19 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 16 11 21 22 32 9 10 17 25 44 13 12 14 20 15 16 19";

// Test 4 // Should say "Player0 Player3" at the bottom private static String test4 = "4 1 10 30 45 66 82 3 25 11 63 78 22 4 13 46 90 5 23 12 6 85 49 88 67 2 44 1 11 31 46 67 83 4 26 12 64 79 23 5 14 47 90 6 24 13 7 86 2 88 68 3 45 1 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 1 2 4 6 8 10 12 14 16 19 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 49 11 44 41 88 42 48 46 43 67 47 2 49";

// Test 5 // Should say "Player0 Player3" at the bottom private static String test5 = "4 2 10 30 45 66 82 3 25 11 63 78 22 4 13 46 90 5 23 12 6 85 49 88 67 2 44 3 6 9 12 15 82 85 5 11 30 1 7 15 10 4 2 8 14 77 38 60 65 17 29 40 1 11 31 46 67 83 4 26 12 64 79 23 5 14 47 90 6 24 13 7 86 2 88 68 3 45 1 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 1 2 4 6 8 10 12 14 16 19 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 49 11 44 41 88 42 48 46 43 67 47 2 49";

// Test 6 // Should say "Player0" at the bottom private static String test6 = "4 2 10 30 45 66 82 3 25 11 63 78 22 4 13 46 90 5 23 12 6 85 49 88 67 2 44 3 6 9 12 15 82 85 5 11 30 1 7 15 10 4 2 8 14 77 38 60 65 17 29 40 1 11 31 46 67 83 4 26 12 64 79 23 5 14 47 90 6 24 13 7 86 2 88 68 3 45 1 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 1 2 4 6 8 10 12 14 16 19 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 49 9 22 1 7 13 46 15 10 90 4";

// Test 7 // Should say "Player2" at the bottom private static String test7 = "3 2 10 30 45 66 82 3 25 11 63 78 22 4 13 46 90 5 23 12 6 85 49 88 67 2 44 3 6 9 12 15 82 85 5 11 30 1 7 15 10 4 2 8 14 77 38 60 65 17 29 40 2 11 31 46 67 83 4 26 12 64 79 23 5 14 47 90 6 24 13 7 86 2 88 68 3 45 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 44 47 49 1 2 4 6 8 10 12 14 16 19 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 49 5 12 14 16 20 19";

public static void main(String[] args){ // To run one of the above tests You can replace System.in with the test variable ie: // Scanner scan = new Scanner(test1); // Be sure to only have one scanner object at a time // Otherwise you can still use the console to enter data Scanner scan = new Scanner(test1);

System.out.println("Enter how many players there are"); Player[] players = new Player[scan.nextInt()];

for(int p = 0; p

Bingo bingo = new Bingo(players); System.out.println("Please enter how many numbers will be called"); int[] calledNums = new int[scan.nextInt()]; System.out.println("Please enter " + calledNums.length + " numbers to be called in order"); for(int i = 0; i

We want to write a Java program to simulate a simplified version of bingo game. Players use cards that feature five columns of five cells each (a 5x5 matrix), with every cell containing a number between 1 to 90. In each step of the game a number between 1 and 90 is called randomly and players need to mark the number in their card if they have it. The first player who marks all of the numbers in one row of one of his/her cards is the winner of the game. Following is the skeleton of the classes that you need to complete: /Iclass Bingo should have an array of Player objects as its instance field. class Bingo public Bingo (Player players) Creates an object of Bingo game using an array of Player objects passed as an argument. public String play (int number): This is the main method for playing the game. It takes a number (the number that is called) and marks the cells with that number in all players' cards. It also returns the name of the winner, if any. If there is no winner, it return an empty string. If there is more than one winner, it returns the name of all winners as one string, separated by space (again, no space We want to write a Java program to simulate a simplified version of bingo game. Players use cards that feature five columns of five cells each (a 5x5 matrix), with every cell containing a number between 1 to 90. In each step of the game a number between 1 and 90 is called randomly and players need to mark the number in their card if they have it. The first player who marks all of the numbers in one row of one of his/her cards is the winner of the game. Following is the skeleton of the classes that you need to complete: /Iclass Bingo should have an array of Player objects as its instance field. class Bingo public Bingo (Player players) Creates an object of Bingo game using an array of Player objects passed as an argument. public String play (int number): This is the main method for playing the game. It takes a number (the number that is called) and marks the cells with that number in all players' cards. It also returns the name of the winner, if any. If there is no winner, it return an empty string. If there is more than one winner, it returns the name of all winners as one string, separated by space (again, no space

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!