Question: Hello. I would like help with question number 7 please. 7. Modify the dealCards() method so it accepts and returns an array list instead of

Hello. I would like help with question number 7 please. 7. Modify the dealCards() method so it accepts and returns an array list instead of an array. 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.

Hello. I would like help with question number 7 please. 7. Modify

the dealCards() method so it accepts and returns an array list instead

of an array. 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. As you can see from the photos,

I tried solving it myself with no luck. How to work with

As you can see from the photos, I tried solving it myself with no luck.

How to work with collections and generics Exercise 12-1 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. Ace of Spades | 2 of Spades 3 of Spades | 4 of Spades ... King of Hearts Jack of Clubs King of Diamonds | 9 of Hearts ... Chapter 12 Use an array list FOUR HANDS OF 2 CARDS King of Hearts King of Diamonds Jack of clubs | 3 of Spades 19 of Hearts 5 of Heartel 8 of clubs Jack of Hearts CARDS LEFT IN DECK: 44 DECK SHUFFLED DECK 4. Open the project and add the required import statement 1. Open the project named ch12_exl_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 array list, set its capacity to 52 since that's the maximum number of cards. 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 shuffle Deck() 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. 8. 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. ols Window Help 2614584 CMD ardDeckApp.java X History System.out.print(""); cards.forEach (card -> { System.out.print(card + "I); }); System.out.println(); } private static void shuffleDeck (ArrayList deck) { for (int i = 0; i deck = getDeck () : displayCards (deck) : System.out.println("SHUFFLED DECK"); shuffleDeck (deck): displayCards (deck); int count = 2, System.out.println("HAND OF " + count + " CARDS"); ArrayList hand = dealCards (deck, count); displayCards (hand) : } //Modified the declaration for the getDeck method so it returns an //array list of strings instead of an array of strings. (3) private static ArrayList getDeck() { ArrayList suits = new ArrayList(); suits.add("Spades"); suits.add("Hearts"); suits.add("Diamonds"); suits.add("Clubs"); ArrayList ranks = new ArrayList(); ranks.add("Ace"); ranks.add("2"); C Deck App main hand CardDedkApp.java X Source History 2 import java.util.Arrays; //Added an import statement to the CardDeckApp file that makes 7/class available. (2) import java.util.ArrayList; 3 4 6 7 8 public class CardDeckApp { //Modify the statement in the main() method that calls the //method so it stores the deck in an array list instead of public static void main(String[] args) { System.out.println("DECK"); ArrayList deck = getDeck(); displayCards (deck); 10 11 12 13 15 System.out.println("SHUFFLED DECK"); shuffle Deck (deck); displayCards (deck); 16 int count = 2: System.out.println("HAND OF " + count + " CARDS"); 20 ArrayList hand = dealCards (deck, count); 21 displayCards (hand); 22 } 23 { / Modified the declaration for the get Deck() method so lt le 24 //array list of strings instead of an array of strings. (3) 25 private static ArrayList getDeck() { 26 ArrayList suits new ArrayList @shuffle Deck for (int i = 0; i deck = new ArrayList(52) : int i = 0; for (String suit : suits) { for (String rank : ranks) { deck.set(i, rank + " of " + suit); i++; } } return deck, } private static void displayCards (ArrayList cards) { System.out.print(""); cards.forEach (card -> System.out.print (card + "); System.out.println(); shuffleDeck for (inti = 0;1 CardDeckApp ndow Help 152 21250.OMB kApp.java X zory IC System.out.print("") cards.forEach (card -> { System.out.print (card + "1"); System.out.println(); } private static void shuffleDeck (ArrayList deck) { for (int i = 0; i dealCards (ArrayList deck, int count) ArrayList hand = Arrays. copyofRange (deck, 0, count) : return hand; } I Deck App dealCards hand

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!