Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please use the pictures at the bottom to help me fix my code. The following is my code, and in bold will be the output.

Please use the pictures at the bottom to help me fix my code. The following is my code, and in bold will be the output. Please tell me what I can do to fix my code to look like the assignments output.

Please BOLD the changes you make to my code to create a better output.

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() { //the following code creates //the deck String[] suits = {"Spades", "Hearts", "Diamonds", "Clubs"}; String[] ranks = {"Ace", "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King"}; String[] deck = new String [52]; int i = 0; for (String suit: suits) { for(String rank : ranks) { deck[i] = rank + " of " + suit; i++; } } return deck; }

private static void displayCards(String[] cards) { //the following code System.out.print("|"); //displays the deck for (String card : cards) { System.out.print(card + "|"); } System.out.println(); }

private static void shuffleDeck(String[] deck) { for (int i = 0; i

OUTPUT:

DECK |Ace of Spades|2 of Spades|3 of Spades|4 of Spades|5 of Spades|6 of Spades|7 of Spades|8 of Spades|9 of Spades|10 of Spades|Jack of Spades|Queen of Spades|King of Spades|Ace of Hearts|2 of Hearts|3 of Hearts|4 of Hearts|5 of Hearts|6 of Hearts|7 of Hearts|8 of Hearts|9 of Hearts|10 of Hearts|Jack of Hearts|Queen of Hearts|King of Hearts|Ace of Diamonds|2 of Diamonds|3 of Diamonds|4 of Diamonds|5 of Diamonds|6 of Diamonds|7 of Diamonds|8 of Diamonds|9 of Diamonds|10 of Diamonds|Jack of Diamonds|Queen of Diamonds|King of Diamonds|Ace of Clubs|2 of Clubs|3 of Clubs|4 of Clubs|5 of Clubs|6 of Clubs|7 of Clubs|8 of Clubs|9 of Clubs|10 of Clubs|Jack of Clubs|Queen of Clubs|King of Clubs| SHUFFLED DECK |Ace of Diamonds|3 of Hearts|King of Diamonds|9 of Spades|2 of Spades|Queen of Spades|8 of Diamonds|7 of Diamonds|3 of Spades|8 of Hearts|4 of Hearts|Queen of Clubs|10 of Diamonds|6 of Spades|5 of Diamonds|5 of Hearts|2 of Clubs|9 of Clubs|2 of Hearts|7 of Spades|3 of Diamonds|Ace of Clubs|Jack of Spades|4 of Diamonds|King of Hearts|5 of Spades|King of Clubs|10 of Hearts|7 of Clubs|8 of Clubs|9 of Diamonds|Queen of Hearts|Ace of Hearts|Jack of Diamonds|3 of Clubs|Queen of Diamonds|5 of Clubs|8 of Spades|Jack of Hearts|Jack of Clubs|Ace of Spades|4 of Clubs|7 of Hearts|10 of Spades|6 of Hearts|9 of Hearts|6 of Diamonds|King of Spades|4 of Spades|2 of Diamonds|6 of Clubs|10 of Clubs| HAND OF 2 CARDS |null|null|

image text in transcribedimage text in transcribed

bookshelf.vitalsource.com VitalSource Bookshelf End-of-Chapter Assignment 2 chapter 12 is Due VitalSource Bookshelf: Murach's Java Programming (5th Edi... Java Question, I Have Marked In Bold My Updates. H... Che... + 3 : Exercise 12-1 Use an array list This exercise has you modify the Card Deck application of exercise 11-4 so it uses array lists instead of arrays for the deck of cards and the hands. m = [ DECK | Ace of Spades | 2 of Spades|3 of Spades|4 of Spades.... SHUFFLED DECK King of Hearts Jack of clubs King of Diamonds | 9 of Hearts ... FOUR HANDS OF 2 CARDS King of Hearts King of Diamonds Jack of Clubs | 3 of Spades | 19 of Hearts 5 of Hearts | 8 of Clubs | Jack of Hearts CARDS LEFT IN DECK: 44 ] Open the project and add the required import statement 1. Open the project named ch12_ex1_CardDeck in the ex_starts directory. Then, review the code for this application and run it to refresh your memory on how it works. 2. Add an import statement to the Card DeckApp file that makes the ArrayList class available. Modify the application to use array lists 3. Modify the declaration for the getDeck() method so it returns an array list of strings instead of an array of strings. Then, modify the code in this method so it stores the cards in an array list instead of an array. When you declare the bookshelf.vitalsource.com VitalSource Bookshelf End-of-Chapter Assignment 2 chapter 12 is Due VitalSource Bookshelf: Murach's Java Programming (5th Edi... Java Question, I Have Marked In Bold My Updates. H... Che... + 6 !!! OURO Modify the application to use array lists 3. Modify the declaration for the getDeck() method so it returns an array list of strings instead of an array of strings. Then, modify the code in this method so it stores the cards in an array list instead of an array. When you declare the array list, set its capacity to 52 since that's the maximum number of cards. 4. Modify the statement in the main() method that calls the getDeck() method so it stores the deck in an array list instead of an array. 5. Modify the displayCards() method so it accepts an array list instead of an array. Since the code for this method uses an enhanced for loop, no additional changes are needed. 6. Modify the shuffleDeck() method so it accepts an array list instead of an array. Then, modify the code for this method so it uses the array list. 7. Modify the dealCards() method so it accepts and returns an array list instead of an array. Then, modify the code for this method so it gets and removes the specified number of cards from the deck and adds them to the hand. Delete the import statement for the Arrays class since it's no longer needed. Then, modify the statement in the main() method that calls the dealCards() method so it stores the hand in an array list instead of an array. Test the application to be sure it works like it did before. bookshelf.vitalsource.com VitalSource Bookshelf End-of-Chapter Assignment 2 chapter 12 is Due VitalSource Bookshelf: Murach's Java Programming (5th Edi... Java Question, I Have Marked In Bold My Updates. H... Che... + 3 : Exercise 12-1 Use an array list This exercise has you modify the Card Deck application of exercise 11-4 so it uses array lists instead of arrays for the deck of cards and the hands. m = [ DECK | Ace of Spades | 2 of Spades|3 of Spades|4 of Spades.... SHUFFLED DECK King of Hearts Jack of clubs King of Diamonds | 9 of Hearts ... FOUR HANDS OF 2 CARDS King of Hearts King of Diamonds Jack of Clubs | 3 of Spades | 19 of Hearts 5 of Hearts | 8 of Clubs | Jack of Hearts CARDS LEFT IN DECK: 44 ] Open the project and add the required import statement 1. Open the project named ch12_ex1_CardDeck in the ex_starts directory. Then, review the code for this application and run it to refresh your memory on how it works. 2. Add an import statement to the Card DeckApp file that makes the ArrayList class available. Modify the application to use array lists 3. Modify the declaration for the getDeck() method so it returns an array list of strings instead of an array of strings. Then, modify the code in this method so it stores the cards in an array list instead of an array. When you declare the bookshelf.vitalsource.com VitalSource Bookshelf End-of-Chapter Assignment 2 chapter 12 is Due VitalSource Bookshelf: Murach's Java Programming (5th Edi... Java Question, I Have Marked In Bold My Updates. H... Che... + 6 !!! OURO Modify the application to use array lists 3. Modify the declaration for the getDeck() method so it returns an array list of strings instead of an array of strings. Then, modify the code in this method so it stores the cards in an array list instead of an array. When you declare the array list, set its capacity to 52 since that's the maximum number of cards. 4. Modify the statement in the main() method that calls the getDeck() method so it stores the deck in an array list instead of an array. 5. Modify the displayCards() method so it accepts an array list instead of an array. Since the code for this method uses an enhanced for loop, no additional changes are needed. 6. Modify the shuffleDeck() method so it accepts an array list instead of an array. Then, modify the code for this method so it uses the array list. 7. Modify the dealCards() method so it accepts and returns an array list instead of an array. Then, modify the code for this method so it gets and removes the specified number of cards from the deck and adds them to the hand. Delete the import statement for the Arrays class since it's no longer needed. Then, modify the statement in the main() method that calls the dealCards() method so it stores the hand in an array list instead of an array. Test the application to be sure it works like it did before

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

SQL Server Query Performance Tuning

Authors: Sajal Dam, Grant Fritchey

4th Edition

1430267429, 9781430267423

More Books

Students also viewed these Databases questions