Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using JAVA. Improve the card program. Use Scanner. You can now specify the number of players plus the number of cards to draw for each

Using JAVA. Improve the card program. Use Scanner. You can now specify the number of players plus the number of cards to draw for each player. Your program will then draw that many cards for that many players, then display the suits and values of all the cards drawn. Assume you are drawing without replacement, which means that once a card is drawn it cannot be drawn again. There are 52 cards in a deck. A deck consists of four suits (Diamonds, Hearts, Clubs and Spades). Each suit contains 13 values (Ace, 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen and King).

Example Run

Players?

2

Cards?

26

Player 1 is holding:

Eight of Clubs

Four of Spades

Eight of Hearts

King of Spades

Six of Diamonds

Four of Hearts

Two of Spades

Jack of Diamonds

King of Hearts

Two of Diamonds

Five of Hearts

Three of Spades

Five of Clubs

Nine of Spades

Two of Hearts

Seven of Hearts

Six of Spades

Seven of Diamonds

Three of Clubs

Four of Diamonds

Queen of Spades

Queen of Clubs

Five of Spades

Ace of Hearts

Five of Diamonds

Jack of Hearts

Player 2 is holding:

Eight of Diamonds

Ace of Spades

Nine of Clubs

Three of Diamonds

Eight of Spades

Ace of Clubs

Seven of Clubs

King of Diamonds

Jack of Spades

Ten of Clubs

Nine of Hearts

Jack of Clubs

Ten of Diamonds

Queen of Diamonds

Four of Clubs

Three of Hearts

Seven of Spades

Ten of Spades

King of Clubs

Queen of Hearts

Six of Clubs

Ten of Hearts

Six of Hearts

Two of Clubs

Nine of Diamonds

Ace of Diamonds

Assignment Requirements

Create a method that accepts two integer parameters and has a 2-dimensional String array (or String[][]) return type. The method will randomly draw cards from a simulated deck and add them to a string array that is returned after cards are drawn.

Create a method that accepts one String array (or String[][]) parameter and has a void return type. The method will perform the System.out.println() function on all elements of the String array. It will also indicate which cards belong to which players like in the example run.

The main method of the program will receive and validate user input. If the input is valid, it will then call both methods.

User input will be the parameter for the method 1 call

The returned 2d String array from method 1 will be the parameter for the method 2 call

You may choose to use either the console or the Java dialog boxes for data input and output.

If the number of cards to draw is zero or a negative or if the total number of cards would exceed 52, your program should report the error and exit the program: you can do this with System.exit(0)

Perform the following test cases:

Players

Cards

Test run 1

3

15

Test run 2

-1

1

Test run 3

2

-1

Test run 4

10

6

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

More Books

Students also viewed these Databases questions

Question

3. Im trying to point out what we need to do to make this happen

Answered: 1 week ago