Homework Assignment #20 (Lists)

For this assignment, you will be creating a list of strings representing the 52 cards in a standard deck of cards, and then doing some manipulations with it. You do not need to make this into an applet or servlet. A stand-alone Java application is fine. You may find the code you write here useful when doing your project.

In your program, you will first create a list of 52 strings representing the 52 cards in a standard deck. Remember that there are four suits (hearts, diamonds, spades, and clubs) containing 13 cards each (numbers 2-10, jack, queen, king, and ace). You can represent each card as a string however you like (e.g., "Q♣", "queen of clubs", "Qclub") as long as it's clear which card is which. I don't recommend writing out fifty-two different add() commands. There's an easier way to do that. (Hint: it involves two nested for loops.) When your program has created the list, it should print the list, so that we can see all the cards.

Next, you will randomize the order of the strings in your list, using the Collections.shuffle() method from the java.util package. Again, print the list, so that we can see the deck.

Finally, you will remove the first five elements of the deck, putting them into a new list. Print the new five-element list and then print the remaining 47 cards in the original deck.

We'll be looking at your source code as well as the results. So make sure that you actually implement the deck of cards as a list of strings, and make sure that when you've removed the five cards, there are only 47 cards left in your original list.

When you've created and compiled your program, make sure to set read permissions for everyone on both the source code .java file and the compiled .class file. Then log on to the class OnCourse page, go to the Assignments tab, and submit your assignment there. Remember to include the path and filenames with your submission!

This assignment is due Wednesday, July 30th before class.