Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

(a) This class should contain an ArrayList (whose capacity can be initialized to

ID: 3640577 • Letter: #

Question

(a) This class should contain an ArrayList (whose capacity can be initialized to 52).

(b) The constructor for this class should ?ll the ArrayList with 52 Card objects
(c) A Deck should also contain a draw() method, which returns the next card in the deck. For simplicity, you may want to simply remove the ?rst Card from the ArrayList, and return it as the drawn card. This means that the size of the ArrayList will shrink as you draw more cards, and you will need to recreate the deck before you use it again.
(d) Deck class should also include a shuffle() method. This method should change the order of the Cards in your ArrayList. The simplest way to do this is to remove randomly-selected cards from the deck, one at a time, and replace them at the end of the deck. For example, you might remove the fourth card in the deck and place it in the last position. By repeating this a number of times, you can be assured that the deck will be somewhat randomized. To generate random integers, use the Random class in the java.util package; see the slides for examples of how to use Random.
(e) Deck class should also include a toString() method that returns a String containing the current contents of the deck, in order

Explanation / Answer

I don't know exactly what your Cards class is supposed to look like, so I just used a String. It shouldn't be too difficult to change it to fit your Card class if you want to. import java.util.ArrayList; import java.util.List; import java.util.Random; public class Deck { List cards = new ArrayList(); Random r = new Random(); public Deck() { for (int i = 1; i