Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

- USE JAVA _ USE A STACK ADT Program a simple game that shuffles a deck of 52 cards and hands them out to two

- USE JAVA

_ USE A STACK ADT

Program a simple game that shuffles a deck of 52 cards and hands them out to two players randomly (26 each). This game will NOT be a simulation, but rather a player vs computer game, where, in each round, both the computers card and the players card are displayed on the screen. The player can then make a decision whether to play that card or choose the second card instead. The player may not look at the second card before making the decision. If the player chooses to play the second card, the first card is placed at the bottom of the players card deck. The higher card wins wins any given round. The winner of that round takes both cards and adds it to a stack of won cards. In essence, there are four stacks. Each player has one stack of cards they are playing with and one stack of cards they have won. There are 26 rounds, since each player has half a stack of cards. At the end of the game, the player with the most cards in their won pile wins.

Note: The deck of cards can simply hold an integer between 0 and 51. The higher number wins. Dont worry about implementing suits like spades, hearts, etc. In the last round, youll notice that you can only play one card no matter what, so even though the user enters 0 the card played is still the same.

Sample run :

Round 1 P1 card: 7 P2 card: 47

Would you like to play the first card? 1 for yes, 0 for no 1

Cards played for this round: P1 card: 7 P2 card: 47 P2 wins this round!

Round 2 P1 card: 51 P2 card: 45 Would you like to play the first card? 1 for yes, 0 for no 1

Cards played for this round: P1 card: 51 P2 card: 45 P1 wins this round! ...

(Rounds 3-25 omitted for brevity) ...

Round 26 P1 card: 22 P2 card: 24 Would you like to play the first card? 1 for yes, 0 for no 0

Cards played for this round: P1 card: 22 P2 card: 24 P2 wins this round!

P1 won: 28 P2 won: 24

P1 wins the game.

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

DB2 11 The Database For Big Data And Analytics

Authors: Cristian Molaro, Surekha Parekh, Terry Purcell, Julian Stuhler

1st Edition

1583473858, 978-1583473856

More Books

Students also viewed these Databases questions