Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java Main topics: Multiple Classes Declaring / Using Instance Variables Driver Classes Program Specification: You are to write a Class Deck which emulates a full

Java

Main topics:

Multiple Classes

Declaring / Using Instance Variables

Driver Classes

Program Specification:

You are to write a Class Deck 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, Jack, Queen, King) in each suit. This of course makes for a total of 52 playing cards in the deck.

Mandatory Instance variable:

private boolean[] deck = new boolean[52];

Mandatory Instance and Class methods:

public void initDeck()

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

// pressent - not delt yet.

public boolean emptyDeck()

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

// have already been delt.

public int dealCard()

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

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

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

// no longer available.

public static String cardToString(int card)

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

// an appropriate String repressentation of this card

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

// to the cards described above.

You are also to write a Driver Class DeckDriver to test your Deck class.

Mandatory Functionality:

Your driver class must minimally print all the cards in the deck in the random order that they are dealt.

Rules and Requirements:

All access to the instance variable(s) in your deck classes instance methods must be made via this.

Notes and Hint:

1. You should be able to re-use much of your methods code from Program 1 in writing your deck class.

2. You should be able to re-write your main method from Program 1 into your driver class with minimal modification / effort.

Lastly you are to write a second deck class SmartDeck which adds a second instance variable cardsDealt that at all times contains the number of cards dealt since that last call to initDeck()

Notes and Hint:

1. cardsDealt will need to be modified by initDeck(), and dealCard(), and will allow you to write emptyDeck() without the use of a loop.

2. Your DeckDriver class must also work identically whether myDeck is declared as Deck or SmartDeck.

Sample run(s):

Run 1: - with Deck class -

-----------------------------------------------------------

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

Run 2: - with SmartDeck class -

-----------------------------------------------------------

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 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

Question

What is meant by planning or define planning?

Answered: 1 week ago

Question

Define span of management or define span of control ?

Answered: 1 week ago

Question

What is meant by formal organisation ?

Answered: 1 week ago

Question

What is meant by staff authority ?

Answered: 1 week ago