| 6.170 | Laboratory in Software Engineering Spring 2002 Problem Set 2: Implementing an Abstract Data Type Due: Tuesday, February 19, 2002 at 4pm |
Quick links:
Contents:
We recommend that you read the entire problem set before you begin work.
To complete this problem set, you will need to know
Answer the following questions, writing your answers in the file
problem1.txt.
CLUBS, DIAMONDS,
HEARTS, and SPADES in
CardSuit static?
public static final int CLUBS = 1; public static final int DIAMONDS = 2; public static final int HEARTS = 3; public static final int SPADES = 4;
CardSuit constructor checks to see if the
parameter suitName is null before using
it. Why isn't this also checked against
null before it is used? (this is
dereferenced implicitly when accessing, say,
smallSuitIcon.)
CardValue and
CardSuit constructors be private?
CardValue need to override
Object.equals?
CardValue implement
the Comparable
interface, as opposed to just creating a method with a different
name and signature like boolean isLessThan(CardValue
v)? (It might be helpful to follow the link to the Java
API docs for Comparable.)
Read through the provided skeletal implementation of Card
in Card.java. The most significant parts of
the provided file are the comments describing how you are to use the
provided fields to implement this class.
Fill in an implementation for the methods in the specification of
Card. You may define new private helper methods if you
want to, but you probably won't need to.
Also, we have provided a fairly rigorous test suite in CardTest.java. You can run the given test suite with JUnit as you program and evaluate your progress and the correctness of your code.
To run the Card test suite, type the following command:
athena% java junit.swingui.TestRunner ps2.playingcards.CardTestFor a non-graphical alternative method of running JUnit, use
junit.textui.TestRunner instead of
junit.swingui.TestRunner, as stated in the Hints.
Indicate clearly as a comment in your source code whether or not your code passes all the tests. We will assume that your code fails if you say nothing.
We have provided a test suite in DeckTest.java. You can run the given test suite with JUnit as you program and evaluate your progress and the correctness of your code.
Indicate clearly as a comment in your source code whether or not your code passes all the tests. We will assume that your code fails if you say nothing.
evaluateHand and compareSamePokerRankings in
TwoPair.java and Straight.java, which are two sub-classes of
PokerRanking. You will need to look at the documentation for the
Hand class.
You will also probably find it helpful to look at the
documentation for the PokerRanking class, since it contains helper
methods like findNOfAKinds, removeNCardsWithValue,
and isValidHand that could be useful.
We have provided test suites in TwoPairTest.java and StraightTest.java (you may also need to refer to the test suites' superclass GeneralRankingTest.java).
Indicate clearly as a comment in your source code whether or not your code passes all the tests. We will assume that your code fails if you say nothing.
You (and your TA) may find it useful if you use Visio to generate the MDD's. Refer to the Tools Handout for more information about Visio.
athena% java ps2.PokerGameAt the beginning of the game, you have a bankroll of $1000. Play against the computer until you have a bankroll of at least $1500. Provide a screen shot of the application at this point. You can create screen shots on Athena by using the xv Grab command:
athena% add graphics athena% man xvOr, if on a Windows machine, you can use Alt-PrtScn.
End of Problem Set 2. Please see Problem Set
Submission instructions.
The following classes are all provided for you, in compiled form, by the staff:
If you are doing the problem set on Athena, then you can easily get
all the source files by running the command get-ps2-files.
If you are not doing the problem set on Athena, then you will have to
get the files yourself from /mit/6.170/www/psets/ps2/src.
Some of the provided code is in the package
ps2.playingcards, and some is in ps2.hand.
Java requires that the directory structure follows the package
structure. So, when you copy the files, you will need to put them in
the following directory structure on your machine:
Fill in the skeleton source files, and test your implementation. You do not need to compile the other sourcecode files that we have provided; compiled classfiles are already ready for your use in the 6.170 locker.ps2/ playingcards/ CardSuit.java CardSuitTest.java CardValue.java CardValueTest.java Card.java CardTest.java Deck.java DeckTest.java hand/ TwoPair.java TwoPairTest.java Straight.java StraightTest.java GeneralRankingTest.java
See the specifications for the classes you will implement and those that are provided for you.
By the end of the problem set, you should have the following files in
the ~/6.170/ps2/ directory on Athena, ready to submit:
ps2/problem1.txt
ps2/playingcards/Card.java
ps2/playingcards/Deck.java
ps2/hand/TwoPair.java
ps2/hand/Straight.java
JUnit reloads all of your classes each time you run a test, so you don't need to restart the JUnit application after making changes to your Java code (though you do need to recompile your code for the changes to take effect).
For a non-graphical alternative method of running JUnit, use junit.textui.TestRunner instead of junit.swingui.TestRunner .
The provided test suites in problem set 2 are the same ones we will be using to grade your implementation; in later problem sets the staff will not provide such a thorough set of test cases to run on your implementations, but for this problem set you can consider the provided set of tests to be rigorous enough that you do not need to write your own tests.
Saturday, February 16, 2002
The StraightFlush.class file was recently added to "ps2-lib.jar", the absence of which was causing various errors being reported by students. If you are on Athena, you should be all set. If you manually copied "ps2-lib.jar" to your local machine or directory, please get the updated jar file.
Friday, February 15, 2002
As pointed out by one of your classmates, CardSuitTest did not work
because the CardSuit.compareTo() was not throwing a
NullPointerException when it received a null input. The error has been
fixed. Download the new CardSuit.java file. If you are
on Athena, simply copy the file
"/mit/6.170/www/psets/ps2/src/CardSuit.java".
Thursday, February 14, 2002
Important Update on PS2:
There were a number of small issues with Problem Set 2 that have now been cleared up:
If you have already started the problem set, we recommend you back up your work and run the script "get-ps2-files" again. You can then copy any code you have already implemented over to the new, fully-specified files (don't worry, none of your code should go to waste!)
To avoid reading an older, cached version of the Problem Set, make sure you Refresh/Reload the relevant pages in your web browser.
junit.jar and
ps2-lib.jar from the /mit/6.170/lib
directory. However, your code MUST work on Athena, so please take a
few minutes before submission of your exercises to ensure that it
runs correctly on Athena.ps2-lib.jar]junit.jar]$Id: ps2.html,v 1.19 2002/02/16 07:48:17 kalpak Exp $