COMP1400 – Programming for Designers

Class announcements for Programming for Designers

COMP1400 – Programming for Designers random header image

lab 5 – lists

Posted by on August 11th, 2011 · Lab

Your task today is to implement a program to represent decks and hands of playing cards.

  1. Download the cards.zip file and uncompress it. It contains an incomplete BlueJ project called cards.
  2. Open the project and inspect the classes:
    • Card – this represents a single playing card.
    • Deck – this represents a deck of cards. The constructor has been written but the methods need to be completed.
    • Hand – this represents a hand of cards drawn from the deck. The fields, constructor and methods all need to be implemented.
  3. Complete these classes following the comments. Do the Deck class first then the Hand class.

To complete the Deck.draw() method you will need to use the Random class in the Java API. This class provides a random number generator to pick random numbers.

To use this class you will have to import it, by putting the line:

import java.util.Random

at the top of your code.

Read the documentation to find out what constructors and methods the Random class provide.

To see what the class does, try typing the following into the Codepad:

import java.util.Random;
Random rng = new Random();
rng.nextInt(6)
rng.nextInt(6)
rng.nextInt(6)
rng.nextInt(20)
rng.nextInt(20)

No Comments so far ↓

There are no comments yet...Kick things off by filling out the form below.

You must log in to post a comment.