| 6.170 | Laboratory in Software Engineering Spring 2004 Problem Set 1: Implementing an Abstract Data Type Due: Thursday, February 12, 2004 at 9pm |
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
Make sure you have followed the instructions on the tools handout relevant to directory setup before you begin development. Furthermore, be sure you have read the problem set procedure handout before you begin.
You can get the source files for problem set 1 by using CVS. Follow
the problem set checkout
instructions and checkout the ps1 module from your repository.
Your code MUST work on Athena, so if you choose to work on a non-Athena machine, please take a few minutes before submitting your solution to ensure that it runs correctly on Athena. Once everything is in order, read the Problem Set Submission instructions for how to run a final check of your code and turn it in.
Answer the following questions, writing your answers in the file ~/6.170/workspace/ps1/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
nullbefore it is used? (this is
dereferenced implicitly when accessing, say,
smallSuitIcon.) CardValue and
CardSuit constructors be private? CardValue or CardSuit need to
override Object.equals? CardValue and
CardSuit 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.)If you are using Eclipse, refresh your ps1 project after creating
problem1.txt (right-click on ps1 in the
package explorer and select 'refresh'). problem1.txt
should now appear in the package explorer along with your source
files. If you are not using Eclipse, remember you will need to
explicitly add problem1.txt to your CVS repository using
the cvs command line.
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.
You'll notice that all of the methods that you need to implement currently have this method body:
throw new RuntimeException("Method is not yet implemented!");
Try compiling your code and running the tests (see below). You'll
notice that each of the tests that calls one of these methods prints
out the error message "Method is not yet implemented", and then shows
a backtrace. The backtrace shows the filenames and line numbers of
the statement that threw the exception, the statement that called the
method that contained the statement that threw the exception, and so
on up to the main method that kicked everything off. When you
implement a method, you should be sure to remove the throw new
RuntimeException statement.
Now fill in an implementation for each of 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.
We have also 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. For this problem set you do not need to write your own test cases.
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.
JUnit is integrated with Eclipse, so you can run the test suite from within the IDE.
Card, you should select CardTest from the
ps1 classes.If you are not using Eclipse, you can invoke JUnit from the command
line. To run the Card test suite, type the following
command:
athena% java junit.swingui.TestRunner ps1.playingcards.CardTest
For a non-graphical alternative method of running JUnit, use junit.textui.TestRunner
instead of junit.swingui.TestRunner.
Remember that in order for this to work, ps1-lib.jar,
junit.jar and the directory containing your class files
must all be in the Java VM's classpath (i.e. part of the CLASSPATH
environment variable or you may need to explicity use the
-classpath parameter for the Java VM).
We have again provided a test suite, in DeckTest.java. You can run the given test suite with JUnit as you program, to 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.
We have provided test cases in HandTest.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.
Now that you have implemented all parts of the poker application, you are ready to play the game.
Follow the instructions below:
ps1.PokerGame
as the main class and then click Run
Run the game by typing the following command:
athena% java ps1.PokerGame
Before invoking Java, make sure you have set up your classpath properly, as outlined earlier.
~/6.170/workspace/ps1/problem5.txt. Your grade will not
depend on your score, but we may post the high scores for fun.
End of Problem Set 1
(Please see Problem Set Submission instructions)
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 from the command line, instead of junit.swingui.TestRunner .
The provided test suites in problem set 1 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 and you will have to write your own test cases. Nonetheless, 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.
We strongly encourage you to use the 6.170 Zephyr Instance. The instance can be used to get in touch with classmates and any lab assistants on duty.
ps1-lib.jar file. The CVS update
will not overwrite any code you have written, nor does it change any
of the specifications in the problem set. ps1-lib.jar is
checked out to ps1/lib/$Id: ps1.html,v 1.19 2004/02/12 05:07:46 jaz Exp $