CIS 35A: Introduction to Java Programming

Home | Green Sheet | Lectures | Assignments | FAQ | Grades | Students

Lab #9 (Exercise 10-4)

Work with a deck of cards

Due Date: Wednesday of Week 3
15 points

In this lab, you'll write an application that uses a variety of arrays and for loops to work with a deck of cards.

  1. Open the CardDeckApp class.
  2. Create an array whole elements hold the first initial of the four different suits (H=Heart, C= Club, S=Spade, D=Diamond. Each suit contains 13 cards) in a card deck. Declare an array that can hold a representation of the cards in a deck of cards without jokers.

  3. Write a method to load the card array, one suit at a time. (Use the numbers 11, 12, and 13 to represent Jacks, Queens, and Kings respectively, and use the number 1 to represent Aces.) Write another method to print the cards in the array, separating each card by a space and printing each suit on a separate line. Call these two methods from the main method. Compile the application and test it to be sure the array is loaded properly.

  4. Write a method that shuffles the deck of cards. To do that, this method should get a number between 1 and 51 by multiplying the result of the random function by 50, converting it to an integer, and adding 1. Then, it should switch each card in the deck with the card that is the given number of cards after it (if there is one). this should be repeated 100 times to shuffle the deck thoroughly. Call this method from the main method, followed by the method that prints the cards array. Test the application to be sure that the cards are shuffled.

  5. Declare a rectangular array that represents four hands of cards with five cards each. Write a method that loads this array by dealing cards from the cards array. Be sure to deal one card at a time to each hand. Write a method that prints the hands, separating the cards in each hand by a space and printing each hand on a separate line. Test the application to be sure that the cards are dealt properly.

Include in your program the following comments:
  • Name of program
  • Team's name with all the names of the members (e.g. Team A: John Doe, Jane Smith, etc.)
  • Current Date
  • Computer system and compiler you are using
  • Brief description of the program

Compile and run the Java program.

When you are ready, upload the java program by clicking the link below:

Upload Lab

I cannot grade if I don't get the file and receive your email.