Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

project ch11_ex4_CardDeck includes the following class CardDeckApp.java public class CardDeckApp { public static void main(String[] args) { System.out.println(DECK); String[] deck = getDeck(); displayCards(deck); System.out.println(SHUFFLED DECK);

image text in transcribed

project ch11_ex4_CardDeck includes the following class

CardDeckApp.java

public class CardDeckApp {

public static void main(String[] args) { System.out.println("DECK"); String[] deck = getDeck(); displayCards(deck);

System.out.println("SHUFFLED DECK"); shuffleDeck(deck); displayCards(deck);

int count = 2; System.out.println("HAND OF " + count + " CARDS"); String[] hand = dealCards(deck, count); displayCards(hand); }

private static String[] getDeck() { String[] deck = new String[52]; // add code that creates deck here return deck; }

private static void displayCards(String[] cards) { // add code that displays cards here }

private static void shuffleDeck(String[] deck) { int randomIndex = (int) (Math.random() * deck.length-1); // add code that shuffles the deck here }

private static String[] dealCards(String[] deck, int count) { String[] hand = new String[count]; return hand; } }

1. Use proper statement indentation and meaningful variable names in the code.

2. Add a multi-line description of this application that also includes your name and the date written at the beginning of the code.

3. Add appropriate descriptive comments to each line of code you add to the project explaining why the code is in the application.

cise 11-4 Work with a deck of cards In this exercise, you'll with a deck of cards. When you finish this exercise, it should display output that looks something like this: write an application that uses arrays and loops to work DECK Ace of Spades |2 of Spades |3 of Spades |4 of Spades | SHUFFLED DECK 18 of Clubs Jack of Hearts 4 of Hearts 9 of Hearts]... HAND OF 2 CARDS 8 of Clubs Jack of Hearts | 1. Open the project named chll ex4 CardDeck in the ex_starts directory. Then, open the CardDeckApp class. Note that this class provides methods for getting a deck of cards, which is an array of strings, as well as methods for displaying cards, shuffling the deck, and dealing cards. 2. Add code to the getDeck) method so it returns a standard deck of 52 cards To do that, create one array of strings for the four suites (Spades, Hearts, Clubs, and Diamonds), and a second array of strings for the 13 ranks for each suit. Then, use nested loops to create a deck of 52 cards 3. Add code to the displayCards( method so it prints all cards in the array that's passed to it. Separate each card with a pipe character. Test the application to be sure the code gets and displays the deck properly Add code to the shuffleDeck(0 method that shuffles the deck of cards. To do that, this method can loop through each card in the deck and swap the current card with another card that's randomly selected. Test the application to be sure that the cards are shuffled. 4. the specified number of cards from the cards array. Test the application to be sure that the cards are dealt properly. Note that this doesn't remove the cards from the deck. As a result, it only works correctly for the first hand. In the next chapter, you'll learn an easy way to solve this issue. 5. Add code to the dealCards( method that creates a hand of cards by dealing

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

Online Market Research Cost Effective Searching Of The Internet And Online Databases

Authors: John F. Lescher

1st Edition

0201489295, 978-0201489293

More Books

Students also viewed these Databases questions

Question

2. What is the impact of information systems on organizations?

Answered: 1 week ago

Question

Question Can a Keogh plan fund be reached by the owners creditors?

Answered: 1 week ago

Question

Question What happens to my plan if I die?

Answered: 1 week ago