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:  The cards currently in the deck are randomly shuffled.
   
   public void reInit(); 
   // Post:  The deck is refilled in order: 2 of clubs .. ace of spades 
   
   public void deal(int n); 
   // Pre:  There are still n cards in the deck
   // Post:  The "top" n cards are printed and removed from the deck

   public void showIt();
   // Post: All cards in the deck are displayed
Of course, there should also be a constructor and any other necessary methods, including a main() method which tests your Deck class. Also consider implementing a toString() method. It should be easy to implement once you've thought about the showIt() method. The deck should be implemented as an array of CardInterface.

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.

Please note that this assignment is not simply asking you to type the (similar) methods given as examples in the Core Java text. Try doing this assignment without even referring to those.

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 13 for the Wednesday lab and Monday, February 14 for the Thursday lab. 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.

Back to:

  • CS 136 home page
  • Andrea Danyluk's home page
  • CS Department home page
  • andrea@cs.williams.edu