CS 3500 Assignment #1 Assigned: Friday, 7 September 2012 Due: Friday, 14 September 2012 The purpose of this assignment is: * To review basic Java programming concepts * To review static methods in Java * To review the Java API (application programming interface) * To acquaint you with the development system you choose to use * To learn the required process for submitting homework in this course * To begin our study of abstraction-based software design with an algebraic specification for an abstract data type of immutable sets You will complete an implementation in Java of the FSet ADT that is specified below. Collaboration between students is forbidden on this assignment. You are responsible for keeping your code hidden from all other students. Turn in your work on this assignment before 10 pm on the due date by following instructions on the course's main assignments web page, http://www.ccs.neu.edu/home/vkp/3500-fl12/Assignments.html Your file of Java code should begin with a block comment that lists 1. Your name, as you want the instructor to write it. 2. Your email address. 3. Any remarks that you wish to make to the instructor. 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 above for submitting your work. Late assignments may be discounted, and very late assignments may be discarded. -------------------------------------------------- Your assignment is to write the code for a single file, FSet.java, that implements the specification below. A test program (/net/course/cs3500vkpf12/Assignments/A1/TestFSet.java) will be provided. -------------------------------------------------- Specification of the FSet ADT. 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 Sun's Java 2 Runtime Environment, Standard Edition, version 1.6.0. 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: Signature: Static methods: emptySet : -> FSet insert : FSet x Double -> FSet add : FSet x Double -> FSet size : FSet -> int isEmpty : FSet -> boolean contains : FSet x Double -> boolean isSubset : FSet x FSet -> boolean absent : FSet x Double -> FSet 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). Algebraic specification: FSet.add (s, k) = s if FSet.contains (s, k) FSet.add (s, k) = FSet.insert (s, k) if ! (FSet.contains (s, k)) FSet.size (FSet.emptySet()) = 0 FSet.size (FSet.insert (s0, k0)) = FSet.size (s0) if FSet.contains (s0, k0) FSet.size (FSet.insert (s0, k0)) = 1 + FSet.size (s0) if ! (FSet.contains (s0, k0)) FSet.isEmpty (FSet.emptySet()) = true FSet.isEmpty (FSet.insert(s0, k0)) = false FSet.contains (FSet.emptySet(), k) = false FSet.contains (FSet.insert (s0, k0), k) = true if k.equals(k0) FSet.contains (FSet.insert (s0, k0), k) = FSet.contains (s0, k) if ! (k.equals(k0)) FSet.isSubset (FSet.emptySet(), s2) = true FSet.isSubset (FSet.insert (s0, k0), s2) = FSet.isSubset (s0, s2) if FSet.contains (s2, k0) FSet.isSubset (FSet.insert (s0, k0), s2) = false if ! (FSet.contains (s2, k0)) FSet.absent (FSet.emptySet(), k) = FSet.emptySet() FSet.absent (FSet.insert (s0, k0), k) = FSet.absent (s0, k) if k.equals(k0) FSet.absent (FSet.insert (s0, k0), k) = FSet.insert (FSet.absent (s0, k), k0) if ! (k.equals(k0)) FSet.union (FSet.emptySet(), s2) = s2 FSet.union (FSet.insert (s0, k0), s2) = FSet.union (s0, s2) if FSet.contains (s2, k0) FSet.union (FSet.insert (s0, k0), s2) = FSet.insert (FSet.union (s0, s2), k0) if ! (FSet.contains (s2, k0)) FSet.intersect (FSet.emptySet(), s2) = FSet.emptySet() FSet.intersect (FSet.insert (s0, k0), s2) = FSet.insert (FSet.intersect (s0, s2), k0) if FSet.contains (s2, k0) FSet.intersect (FSet.insert (s0, k0), s2) = FSet.intersect (s0, s2) if ! (FSet.contains (s2, k0)) s.toString() = "{...(" + FSet.size(s) + " elements)...}" Values of the FSet ADT shall also implement the public dynamic methods equals(Object) and hashCode() such that If s1 is a value of the FSet ADT, then s1.equals(null) returns false. If s1 is a value of the FSet ADT, but x is not, then s1.equals(x) returns false. If s1 and s2 are values of the FSet ADT, then s1.equals(s2) if and only if for every Double k FSet.contains (s1, k) if and only if FSet.contains (s2, k) If s1 and s2 are values of the FSet ADT, and s1.equals(s2) then s1.hashCode() == s2.hashCode(). --------------------------------------------------