CS 136 Assignment 1

Description

In this assignment you create classes to implement a deck of playing cards. The assignment has two parts. In part 1, you implement a Deck class using the CardInterface interface and Card class discussed in lecture. The Deck class should provide the following methods
   public void shuffle(); 
   // Post:  Randomly shuffles the cards in the deck
   
   public void reInit(); 
   // Post:  Refill the deck in order: 2 of clubs .. ace of spades 
   
   public CardInterface[] deal(int n); 
   // Pre:  There are still n cards in the deck
   // Post:  The "top" n cards are removed from deck and returned 
Of course, there should also be a constructor and any other necessary methods, including a main() method which tests your Deck class. The deck should be implemented as an array of Card.

The second part of the assignment is to provide a new implementation of the Card class, and then use it in your Deck class. The new card class, called OtherCard, should implement a card as a number between 0 and 51, where 0-12 represents the clubs (2..Ace), 13-25 represent the diamonds, and so on. This will require rewriting of the bodies of several of the methods in the Card class. The easiest way to do this part of the assignment is to copy my Card.java file and edit it. Using OtherCard in place of Card should require only minor modifications to the Deck class if you've been using CardInterface for the types of variable and parameters.

Goals

The goals are to gain experience with the Java programming language, the Metrowerks CodeWarrior Java environment and class design. You should plan your work carefully so that you can complete part one and begin part two in the lab.

Naming Conventions

Classes requested for assignments should always be named as in the assignment. This is necessary for our testing of your work. Also, Java programmers tend to follow certain naming conventions. Constants are all upper-case, classes begin with upper-case, variable and method names begin with lower case, using upper-case for multi-word names. You should also follow these conventions. Finally, names help the reader understand what you have written. Names such as cardList, errorMessage, etc., are preferred (required?) over names such as bozo, spiffy, X326, etc..

What to hand in

The program is due Sunday, February 15. Programs are handed in by putting a folder, whose name is your last name, into the CS136 drop-off folder on Cider Press. The folder should contain the Metrowerks project folders for your OtherCard and Deck classes. The Deck class should include a main method which tests your Deck. Always try to test your classes thoroughly. For example, shuffle, deal some hands, re-initialize, shuffle again, etc., printing the deck contents after each operation.

Sample Program

Here is a sample applet which demonstrates what each method should do. (It will display and execute only if your browser is Internet Explorer 4.0 -- or other browser that can execute Java 1.1 code, otherwise you will simply get an error message.) Of course your program will be an application, rather than an applet, and need not use windows or buttons.



Back to:
  • CS 136 home page
  • Kim Bruce's home page
  • CS Department home page
  • kim@cs.williams.edu