Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

need help with this java project This project provides an opportunity to practice object oriented programming. The intent of this project is to create an

need help with this java project

This project provides an opportunity to practice object oriented programming. The intent of this project is to create an object model of a bingo game, and implement all the classes needed to simulate a collection of players at a bingo competition.

The Bingo Game Overview

The first item that needs to be modeled is the bingo cage which contains 75 bingo balls, each of which has a letter and number (ie. B15). As the game is being played, a random bingo ball is removed from the cage and that bingo balls letter and number are the next value to be played. To begin a new game, all the bingo balls are placed in the cage.

The second item that needs to be modeled is the bingo card which contains 5 columns of 5 numbers. The 5 columns correspond to the letters B, I, N, G, O. Each column contains random values in the following ranges:

Column 0: B 1 thru 15

Column 1: I 16 thru 30

Column 2: N 31 thru 45

Column 3: G 46 thru 60

Column 4: O 61 thru 75

Each spot on the card must be able to be marked as played whenever a bingo ball is played. For instance, if ball N35 is played, and the spot in column 2 row 4 contains a 35, then that spot must be marked in some way to indicate that the number 35 was already played. The center spot on a bingo card is a free spot, so the spot in column 2 row 2 must always be marked as played.

A bingo card must be able to be analyzed for the number of wins it contains. It is possible for multiple wins to result from a single ball being played. A win results from any of the following:

All spots in a row have been marked

All spots in a column have been marked

All spots in either diagonal have been marked

At the start of each new game, all the marks on the card from the previous game must be removed.

The third item that needs to be modeled is the bingo player. Each player has a name. A player can play any number of bingo cards. At the beginning of each new game, a player must clear the marks from all their bingo cards. Whenever a bingo ball is played, a player is informed of the column and number being played. The player plays that column and number on each of their bingo cards. The player checks all cards for the number of wins thus far in the game. Whenever a new game starts, the number of wins from the current game is added to the total wins the player already has.

The fourth item that needs to be modeled is the game manager. The game manager controls the bingo cage and manages all the players participating in a bingo session. The game manager plays a specified number of games in a bingo session. Each game is played until a specified minimum number of wins have been achieved. At the start of each game, the game manager makes sure the bingo cage contains all the bingo balls, and that each player has a chance to unmarked all their bingo cards. The game manager provides each player with column and number information for each bingo ball that is played. The game manager gets the number of wins in the current game per player as each bingo ball is played. The game manager stops a game when the total wins for the current game has equaled or exceeded the minimum wins required. After playing a bingo session, the game manager reports how many wins each player has achieved.

Class Design Details

BingoCage Class

Member Variables:

ArrayList of bingo ball values

Random number generator

Methods:

constructor ( ): makes sure the list of bingo balls is complete

newGame ( ): makes sure the list of bingo balls is complete. Nothing returned.

nextBall ( ): removes a randomly selected ball from the list. Returns its value.

BingoCard Class

Member Variables:

A 2 dimensional array (5x5) of card values where a card value has a number and a mark

Methods:

constructor: creates the 2 dimensional array of card values. Center spot mark is set.

newGame ( ): all marks in 2 dimensional array are cleared. Center spot mark is set.

playBall (column, number): checks card for specified column, number. If present,

that card values mark is set.

checkForWins ( ): returns the number of rows, columns, diagonals where all the card values in that row, column, or diagonal are marked.

displayCard ( ): prints the current card state, row by row, showing both the number and

the mark for each spot. This function is for debugging purposes only.

Player Class

Member Variables:

The players name

An array of BingoCards

The total number of wins

Methods:

constructor (name, numCards): Store the name. Create the requested number of cards.

newGame ( ): add number of wins in current game to total wins. Reset each card.

playBall (column, number): play specified ball value on each card. Return the sum of

the number of wins on each card.

checkForWins ( ): return the sum of the number of wins on each card. (private method)

getName ( ): return the name of the player.

getTotalWins ( ): return the total number of wins.

GameManager Class

Member Variables:

A BingoCage.

An array of Players.

The game number.

Methods:

constructor ( ): determine number of players and the number of cards per player (ask user). Get the names (from user) for each player. Add each player to the game. Example output shown below:

How many players are there?

5

How many cards per player?

5

Enter the names for 5 players.

Dracula Wolfman Frankenstein Mr.Hyde VanHelsing

The players are ready! Let the games begin!

play (numberOfGames, winsPerGame): plays the specified number of games. For each

game, gets ball from cage, distributes column, number to all players, displays

number of wins (>0) so far after each ball. At end of game, prepares cage and

players for a new game. Example partial output shown below:

Starting game 9!

Game 9: There are 1 wins after ball 28

Game 9: There are 2 wins after ball 29

Game 9: There are 2 wins after ball 30

Game 9: There are 3 wins after ball 31

Game 9: There are 3 wins after ball 32

Game 9: There are 4 wins after ball 33

Game 9: There are 4 wins after ball 34

Game 9: There are 4 wins after ball 35

Game 9: There are 6 wins after ball 36

Starting game 10!

Game 10: There are 1 wins after ball 20

Game 10: There are 1 wins after ball 21

Game 10: There are 2 wins after ball 22

Game 10: There are 2 wins after ball 23

Game 10: There are 2 wins after ball 24

Game 10: There are 2 wins after ball 25

Game 10: There are 2 wins after ball 26

Game 10: There are 2 wins after ball 27

Game 10: There are 2 wins after ball 28

Game 10: There are 3 wins after ball 29

Game 10: There are 3 wins after ball 30

Game 10: There are 4 wins after ball 31

Game 10: There are 4 wins after ball 32

Game 10: There are 5 wins after ball 33

displayResults ( ): display the name and total wins for each player as shown below:

Results after 10 games:

VanHelsing : 16 wins.

Dracula : 13 wins.

Wolfman : 11 wins.

Frankenstein : 9 wins.

Mr.Hyde : 4 wins.

Test Class

The main method in the test class will create a GameManager, then call the play method specifying the number of games to be played, and the number of wins per game. Finally the displayResults method is called to see who won!

Development Strategy

Develop the BingoCage class first. Then write a little test code to get all 75 values from the cage and display them. Then call the newGame method and try getting the 75 values again.

When the cage is working, implement the BingoCard class. Then write a little test code to create a card, play all 75 bingo ball values, check for 12 wins, and display the card. Then call the newGame method and display the card again to verify that all but the center spot is in an unmarked state.

Lastly implement the Player class and the GameManager class. The test program main function can simply create a GameManager object and have it create the desired number of players. Then have main call the game managers play method to play 10 games with 5 wins per game. Debug the Player and GameManager classes as needed.

Hints

An ArrayList will be needed for the BingoCage ONLY. This will make life simpler since you will need to remove random values from the bingo ball list. Doing this with a simple array would be possible, but require much more messy code. An ArrayList works as follows:

To create an ArrayList reference variable, do the following:

ArrayList listname;

The datatype is whatever you decide you want to use to represent the possible values of the bingo balls. To create an actual ArrayList object, do the following:

listname = new ArrayList<> ( );

To add a value to the end of an ArrayList, do the following:

listname.add (value);

Note that the data type of the value must be the same as the data type you specified when you created the ArrayList object. To remove an item from the ArrayList at a random position, do the following:

value = listname.remove (position);

The item at the specified position is removed and returned from this function call. This statement stores the returned value into a variable named value that must be the same data type as that specified when the ArrayList was created. The number of items left in the ArrayList can be gotten anytime by doing the following:

numItems = listname.size ( );

An ArrayList can do many other things, but most likely these are the only operations you will need to do for this lab.

To display the final results in order such that the player with the most total wins is displayed first, and the player with the least wins is displayed last, it would be nice to simply use the Arrays.sort function on the array of players in the game manager. In order to do this, you will need to implement the Comparable interface in the Player class. To do this you need to first add the following:

public class Player implements Comparable

Doing this requires that you also add the following function to the Player class:

public int compareTo (Object object) { . }

This method will need to cast the object parameter to a Player in order to access the total number of wins for that object and compare that to the total wins on this object. Simply returning the difference between these two values will sort the list in ascending or descending order based on total wins. By doing the subtraction in the right order, you can have the Player array sorted in descending order so the winner of the most games is the first player in the array.

Documentation

Make sure you document all parts of this project. A description of each class should be included in a Javadoc comment before the start of the class. Every function in each class must include a Javadoc comment describing the purpose, parameters, and return value.

Submission

Create a zip file of the project and upload your zip file to the Pilot drop box before the project due date. Also, copy your source code into ONE text file (preferably Wordpad) and submit that separately to the drop box. The order of the classes in the text file should be BingoCage, BingoCard, Player, GameManager, followed by your test class. Ask your TA for help if you have any questions.

NOTE: If the submitted project does not compile, it will receive zero points.

Rubric (50 pts)

BingoCage works as described. (10 pts)

BingoCard works as described. (10 pts)

Player works as described. (10 pts)

GameManager works as described. (10 pts)

Test program works as described. (5 pts)

Documentation and programming style. (5 pts)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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

Recommended Textbook for

Database Systems For Advanced Applications 18th International Conference Dasfaa 2013 Wuhan China April 22 25 2013 Proceedings Part 2 Lncs 7826

Authors: Weiyi Meng ,Ling Feng ,Stephane Bressan ,Werner Winiwarter ,Wei Song

2013th Edition

3642374492, 978-3642374494

More Books

Students also viewed these Databases questions

Question

discuss the issues, and future of the audit report

Answered: 1 week ago

Question

8. Describe how cultural spaces are formed.

Answered: 1 week ago