====== Assignment 1 ====== ~~NOTOC~~ **CS203** \\ **Spring 2013** \\ **Assigned:** Fri, Feb 1 \\ **Due:** Fri, Feb 8 \\ ===== Summary ===== Implement and test the FSet ADT that is specified below. ((this assignment has been adapted for our use with permission by Viera Proulx)) **Important:** \\ //Read this entire page before you begin. \\ Read this entire page before you begin. \\ Read this entire page before you begin.// ===== Goals ===== * review basic Java programming concepts, including ''static'' methods * review implementing an ADT (Abstract Data Type) with an underlying data structure * review using the Java API (Application Programming Interface) * create a Java project from scratch * use the Tester library to develop a test suite for your project ===== General Guidelines ===== Your Java files should begin with a block comment that lists - Your name. - CS203 - Spring 2013 - Lab 1 / Assignment 1 - Any remarks that you wish to make to me. 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 [[:courses/cs203-201301/recipes|Design Recipe]] (see sidebar) for each method you implement is strongly recommended. ===== Description ===== 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. ===== 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 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: ===== Signatures ===== **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). ===== Main class Implementation Notes ===== 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() ); } } ===== FSet Implementation Notes ===== * The FSet class has no public constructors. The only way for client code to create an FSet is through the static emptySet() method, or through other FSet methods that return an FSet. * While FSet has no public constructors, you will find it useful to have private constructors. These constructors can be called from internal FSet methods, but not external client code. * Your FSet ADT should use an ''ArrayList'' as its underlying implementation. * FSet objects are immutable: methods that might change the contents of an FSet instead return a new FSet (this is like Java's String class). * Be careful: while FSet's are immutable, their underlying ArrayList data structure is not! Don't create new FSet's that share an existing ArrayList. You have been warned. * Now you know why the FSet ADT is so named: it's a //Functional//-style implementation of a Set! ===== Examples class Implementation Notes ===== * If you're following the Design Recipe, you'll put your examples of FSets in the ''Examples'' class, as fields of the class. * Refer to Lab 1's example classes to see how to make examples of your data, and how to write test methods. * In case you don't notice the pattern, all the test methods are named with a prefix of ''test''* -- that's how the Tester knows to run the check-expect's inside those methods. ===== Tester Library Notes ===== 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:** * right-click on the ''Libraries'' component under your project, and select "Add JAR/folder..." * then navigate to ''/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'' ===== Submission Details ===== To submit what you have at the end of lab: \\ ''$ submit203 lab2 '' When you're ready to submit the assignment: \\ ''$ submit203 assign1 '