Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

*JAVA* Our quartet game: Quartet is a card game. We play it in a slightly modified version with two players and points: The cards are

*JAVA*

Our quartet game: Quartet is a card game. We play it in a slightly modified version with two players and points: The cards are dealt to both participating players. The cards all have the same categories of points, for which each card has different values. Each player knows only the top of his cards. He sets this at the beginning of each game round. A player initiates a round by calling a category. All cards used in this category are checked. The player with the highest value in this category wins the round and receives a point. The game ends as soon as all cards have been played. Implement the following classes to program the game: The Card class: The Card class stores four values for the categories together with the fighter's name and affiliation and makes these values available through corresponding get functions. Select "height", "intelligence", "strength" and "jedi power" as categories and select an appropriate data type to store the associated values. Write a suitable constructor to create new maps and also overwrite the .toString method for easy output. Example of a card issued: ####### Player 1: Grogu REBEL height: 0.40 intelligence: 4 strength: 1 jedi power: 9 ####### The Stack class: The Stack class manages a stack of cards. The class must offer the following functions: playCard(): The top card is returned and removed from the stack. showCard (: Outputs the top card in the stack in the console. count (): Returns the number of cards of the stack. Since we play a modified version of quartet in which no cards are added to the stack, you can choose an array as the basic data structure. However, since arrays in Java have a fixed length, you must display missing cards with zero and output the first card in showCard() that is not zero. The Player class: A player has a name, a score and has decks of cards. The stack should be a private object of the class. The score should also be private. Implement the following methods in the class: countCards (): Returns the number of remaining cards in the player's deck of cards addPoint (): Increases the player's score by one getPoints (): Returns the player's score showCard(): Returns the top card in the stack in the console from playCard()): Returns the player's top card and removes However, the playCard () function should differ for the computer and the player, since the player must also specify a category, the computer should not use a transfer value here, but a category should be randomly selected. So two different functions are to be implemented, depending on whether a category has been specified. Use overloading for this. The Quartet class: In this class, the general game mechanics are to be implemented. First, you should create 8 clearly defined cards at the beginning, each with different values and randomly distribute them to the players. For this you need two players, one you control and one that the computer controls. Players should manage their own deck of cards. The first round of the game will be initiated by you. Each subsequent round of the game will be started by the previous winner. For the comparison of the cards, they should be taken from the stacks of the players and the corresponding value compared. The winner contains a point. The compared cards should also be output to the console after each round. The interaction takes place via the command line. The computer plays a random category via Player.playCard (). In order to play yourself, you must use the scanner to read commands from the command line. play: Plays your top card with the given category. show: Outputs the top card. stats: Outputs the number of cards and the score of both players. Think about which of these actions require further arguments and which do not. After both players no longer have cards, the winner should be issued and the program should be terminated.

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