Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java Main topics: Programmer defined methods Random number generators Arrays Program Specification: You are to develop a program which emulates a full deck of playing

Java

Main topics:

Programmer defined methods

Random number generators

Arrays

Program Specification:

You are to develop a program which emulates a full deck of playing cards. That is 4 suits (Clubs, Spades, Hearts, and Diamonds) and 13 ranks (Ace, 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, King) in each suit. This of course makes for a total of 52 playing cards in the deck.

Mandatory methods:

public static void initDeck(boolean[] deck)

// set the values of deck to indicate that they are all

// present - not dealt yet.

public static boolean emptyDeck(boolean[] deck)

// returns whether or not all the cards in the deck

// have already been dealt.

public static int dealCard(boolean[] deck)

// returns a card (an int in the range 0 to 51) at random

// that has not been dealt since the deck was initialize

// via intDeck. Also notes (in deck) that this card is

// no longer available.

public static void printCard(int card)

// given a card (an int in the range 0 to 51) prints

// an appropriate representation of this card based

// on a 1-1 and onto mapping of the set [0, 51] to

// the cards described above.

Rules and Requirements:

Your main method must end with the following block of code, which can not be modified.

boolean[] myDeck = new boolean[52];

final int cardsPerRow = 8;

int cardsThisRow = 0;

int myCard;

initDeck(myDeck);

System.out.println(" Here is a shuffled deck ... ");

while (!emptyDeck(myDeck))

{

myCard = dealCard(myDeck);

++cardsThisRow;

if (cardsThisRow <= cardsPerRow)

{

printCard(myCard);

System.out.print(" ");

}

else

{

System.out.println("");

cardsThisRow = 1;

printCard(myCard);

System.out.print(" ");

}

}

System.out .println( );

Notes and Hint:

1. You should write and test your methods one at a time.

Sample run(s):

Here is a shuffled deck ... 7S KS 2H 6S 4C 2D 9D 9C 4H 7C 9H 3D 5H 5D 10S 2S JH AH 4S KC QC AD QD 7D AS KD 5C 7H KH 3C JC 2C 4D 8H AC 5S 10C JS 3H 9S 8D 10D 8S 6C QH 8C JD 3S QS 6D 10H 6H

Here is a shuffled deck ... 2D 10C AD 6C JC JH KS 4S 9C 9S 2S AC QS 3C 3H 8C 3S QC AS 4D 10S 2C 8S 6D 6S 9H 2H 5S JD KD QH 10D 7H QD 3D 6H 7D 8H 5D 4H KH AH 8D 7C 9D 7S 5C 5H KC JS 4C 10H

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

Advances In Database Technology Edbt 88 International Conference On Extending Database Technology Venice Italy March 14 18 1988 Proceedings Lncs 303

Authors: Joachim W. Schmidt ,Stefano Ceri ,Michele Missikoff

1988th Edition

3540190740, 978-3540190745

More Books

Students also viewed these Databases questions