CS203
Spring 2013
Assigned: Fri, Feb 1
Due: Fri, Feb 8
Implement and test the FSet ADT that is specified below. 1)
Important:
Read this entire page before you begin.
Read this entire page before you begin.
Read this entire page before you begin.
static methods
Your Java files should begin with a block comment that lists
Part of your grade will depend on the quality and correctness of your code, part will depend on the readability of your code (comments and indentation), and part will depend on how well you follow the procedure below for submitting your work. Following the Design Recipe (see sidebar) for each method you implement is strongly recommended.
Your assignment is to develop and test the Java code that implements the FSet specification below. Your project will consist of three files. I’m providing you (below) with the main class for this project (Assign1.java). You will implement: FSet.java and Examples.
FSet.java will contain your implementation of the specification (below), and
Examples.java will use the Tester library to test your implementation of FSet.
FSet is an immutable abstract data type whose values represent finite sets with elements of type Double.
The FSet ADT shall be implemented in Java, and will be tested using the version of Java installed on the Linux workstations in our labs. The code for this implementation shall be in the default package, and shall define a public class named FSet. The operations of the FSet class shall be provided by the following public methods of the FSet class:
Static methods:
emptySet : -> FSet
size : FSet -> int
add : FSet x Double -> FSet
remove : FSet x Double -> FSet
isEmpty : FSet -> boolean
contains : FSet x Double -> boolean
isSubset : FSet x FSet -> boolean
union : FSet x FSet -> FSet
intersect : FSet x FSet -> FSet
Dynamic methods (for which the receiver is an FSet):
toString : -> String
equals : Object -> boolean
hashCode : -> int
Restrictions:
Null arguments may not be passed to any of the above methods
except for equals(Object).
Here is my implementation of the main class for this assignment (Assign1.java):
/* * CS203 * Spring 2013 * Marc Smith * Assign 1 (and lab 2) * Solution */ import tester.Tester; /** * Main class for Assignment 1 * Kicks off the Tester which runs the tests in Examples class */ public class Assign1 { public static void main(String[] args) { Tester.runFullReport( new Examples() ); } }
ArrayList<Double> as its underlying implementation.
Examples class, as fields of the class.
test* – that’s how the Tester knows to run the check-expect’s inside those methods.
You need to import the tester library to compile and run your tests. There are two ways to do this, depending on whether you are running your your project from Netbeans or the command line:
From Netbeans:
Libraries component under your project, and select “Add JAR/folder...”
/home/cs203/jars and select tester.jar
From the command line:
compile your program using:
javac -cp .:/home/cs203/jars/tester.jar *.java
run your program using:
java -cp .:/home/cs203/jars/tester.jar Assign1
To submit what you have at the end of lab:
$ submit203 lab2 <FSet-root-dir>
When you’re ready to submit the assignment:
$ submit203 assign1 <FSet-root-dir>