CSE1030 Lab 03

Week of Jan 27, 2014
Due: Mon Feb 3 before 11:59PM

Introduction

The purpose of this lab is to implement an immutable class that uses static and non-static features.

There is one question in this lab, which should be submitted by the due date.

Question 1: Implement a Playing Card class

Implement a class that represents an immutable playing card from a standard 52 card deck. A playing card is identified by its suit (clubs, diamond, heart, spade) and its rank (two through ten, jack, queen, king, and ace). Both the suit and rank are represented with strings.

Your class must provide the API shown here.

Please start with the skeleton code shown below:

package cse1030.games.cardgames;

/**
 * An immutable class representing a playing card from a standard 52 card deck.
 * A playing card is identified by its suit (clubs, diamond, heart, spade) and
 * its rank (two through ten, jack, queen, king, and ace). Both the suit and
 * rank are represented with strings.
 * 
 * 
 * @author CSE1030_W13_14
 * 
 */
public final class PlayingCard implements Comparable<PlayingCard> {

  // a sorted array of ranks
  private static final String[] RANKS = { "2", "3", "4", "5", "6", "7", "8",
      "9", "10", "J", "Q", "K", "A" };
      
  // a sorted array of suits
  private static final String[] SUITS = { "S", "C", "D", "H" };

  // the rank of this card
  private final String rank;
  
  // the suit of this card
  private final String suit;
  
  

  public static void main(String[] args) {
    // generate a standard 52 card deck
    Set<String> ranks = PlayingCard.getAllRanks();
    Set<String> suits = PlayingCard.getAllSuits();
    for (String r : ranks) {
      for (String s : suits) {
        PlayingCard card = new PlayingCard(r, s);
        System.out.println(card);
      }
    }
  }
}

Notice that PlayingCard has two static attributes that are arrays that hold the valid ranks and suits sorted in ascending order. The arrays are static because there is no need for every card to store a copy of the arrays. The class also has two static methods that you must implement.

A JUnit tester is available here.

Submit your class using the following command:

submit 1030 L3 PlayingCard.java

or use the web-based submit https://webapp.eecs.yorku.ca/submit/