Question: Create a Card class and a Deck class and a driver. A Card is immutable, meaning that after you instantiate it, it cannot be changed.

Create a Card class and a Deck class and a driver.

A Card is immutable, meaning that after you instantiate it, it cannot be changed. The suit property can be "clubs", "spades", "diamonds" or "hearts". The faceValue property can be "Ace", "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", or "King". Use a static array of strings so you can loop through possible values using indexes, and provide public static getter methods for an array of suits (getSuits()) and an array of values (getValues()) to return the arrays. A good toString() method should also be included.

An instantiated Deck contains an ArrayList of 52 Card objects, from "Ace to King" of each suit. There must be a field indexing the current top card in the Deck. A getNext() method should return the top card in the Deck and move to the next top card. A hasNext() method should be true if there is another current top card. A shuffle() method should shuffle the cards into a random order and reset the index of the top Card to 0. One way to shuffle would be to loop 100 times, each time picking two random numbers between 0 and 51 inclusive and swapping the cards at those two indexes.

The driver should instantiate a Deck, shuffle() it and then loop, printing the top card and moving to the next Card, pausing after each for the user to press enter or "q" and then enter to quit. After all Cards in the Deck have been displayed, the Deck should be shuffled.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!