Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Pick 3 Cards program that simulates the action of picking 3 cards from a deck of 52 cards. Your program will display the rank and

Pick 3 Cards

program that simulates the action of picking 3 cards from a deck of 52 cards. Your program will display the rank and suit of each of the cards.

To generate a random number between 0 and 51

To define two enums:

oThe first enum should be defined for the card Suit (Spades, Hearts, Diamonds, Clubs)

oThe second enum should be defined for the card Rank (Ace, Two, Three, ... , Jack, Queen, King)

To create variable of type Suit and a variable of type Rank, as well as variables to store the randomly generated number, a card rank number (e.g. r) and a suit number (e.g. s).

Integer Division to distinguish between the suits in the deck

oConsider the following ranges of integers to represent the cards:

0 to 12 can represent the 13 Spades

13 to 25 can represent the 13 Hearts

26 to 38 can represent the 13 Diamonds

39 to 51 can represent the 13 Clubs

The modulus operator to distinguish between each rank

oA remainder of 0 will represent Ace, remainder of 1 for Two and so on

Two if else-if structures

oThe first if else-if assigns a value to the Rank variable based on the value of r

if r is 0, assign Ace to the Rank variable

Otherwise, if r is 1 assign Two to the Rank variable (and so on)

oThe second if else-if assigns a value to the Suit variable based on the value of s

if s is 0, assign Spades to the Suit variable

Otherwise, if r is 1 assign Hearts to the Suit variable (and so on)

oImportant: Only assignment should be done within the if else structures (NO print or println statements should be within them.) You can display your results after the selections are made.

A loop to repeat the process 3 times.

Sample of the output is shown below:

Your cards are:

Six of Diamonds

Seven of Spades

Ten of Spades

Your cards are:

Nine of Clubs

Seven of Diamonds

Seven of Hearts

tip

You MUST use enums for this question. DO NOT replace the enum and their values with integers or strings!

Remember to write out each rank value as an identifier (e.g. two instead of 2). You cannot use integer or string literals in your enums.

Use a Random object to generate the integer values.

If you have more than 3 println/print statements, then you have too many. J

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

Modern Dental Assisting

Authors: Doni Bird, Debbie Robinson

13th Edition

978-0323624855, 0323624855

Students also viewed these Programming questions