X671: ArrayBag bingo

Write the member method 'playBagBingo()' that implements the player logic for the game described below. Bag Bingo is a game of chance where players randomly "draw" (remove) letter tiles one at a time from a bag of tiles, where each tile is stored as a String. After each tile "draw" the player checks if the removed letter tile helps them form the word "BINGO".

The player must add letter tiles that help to win the game to the keep bag, while letter tiles that do not help to form the word "BINGO" must be added to the discard bag. The player wins when they have drawn all the letters needed to form the word "BINGO".

Note: players must not keep 'extra' tiles, only the tiles they need. For example if a player already has a "B" tile in their keepBag then they must discard any other "B" tile subsequently "drawn" (removed) from the tileBag. The game ends either when the player wins the game or when the tile bag becomes empty.

When the game has ended the player, i.e. the bagBingo() method, must return the discardBag of tiles. Your playBingo method has the following form. ArrayBag playBagBingo(ArrayBag tileBag, ArrayBag keepBag, ArrayBag discardBag)

You may use the following Bag API methods: public int getCurrentSize(); public boolean isEmpty(); public boolean add(T newEntry); public T remove(); public boolean contains(T anEntry);

Hint: It may be helpful to use helper methods like checkIfWon(keepBag)

Your Answer:

Reset

Practice a different Java exercise

Feedback

Your feedback will appear here when you check your answer.