CS U370 Assignment #1 Section: Clinger Assigned: Tuesday, 6 January 2009 Due: Tuesday, 13 January 2009 The purpose of this assignment is: * To review basic Java programming concepts, such as objects, methods, variables, etc. * To introduce the Java API (application programming interface) * To acquaint you with the development system you choose to use * To learn the required procedure for submitting homework in this course * To begin our study of abstraction-based software design by providing an algebraic specification for the Refreshable ADT * To review static methods * To introduce the use of factory methods for creating new objects You will complete an implementation in Java of the Refreshable 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 sending electronic mail to: will@ccs.neu.edu with subject CSU370 assignment 1 and a body that consists of nothing but your Refreshable.java file. That file 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, Refreshable.java, that implements the specification below. For this first assignment, a test program (/course/csu370wc/Assignments/A1/TestRefreshable.java) is provided. (In future assignments, you will be required to develop your own test programs.) -------------------------------------------------- Specification of the Refreshable ADT. The Refreshable 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 will be in the default package, and shall define a public class named Refreshable. That class shall provide the following public static methods: Signature: Refreshable.create : String * int -> Refreshable Refreshable.name : Refreshable -> String Refreshable.era : Refreshable -> long Refreshable.name (Refreshable.create (s, i)) = s Refreshable.era (Refreshable.create (s, i)) = i Values of the Refreshable ADT shall also implement the public dynamic methods equals(Object) and hashCode() such that If v1 and v2 are values of the Refreshable ADT, then v1.equals(v2) if and only if Refreshable.name(v1).equals(Refreshable.name(v2)) and Refreshable.era(v1) == (Refreshable.era(v2)) If v1 is a value of the Refreshable ADT, but x is not, then v1.equals(x) returns false. If v1 and v2 are values of the Refreshable ADT, and v1.equals(v2) then v1.hashCode() == v2.hashCode(). Note: The second argument to Refreshable.create must be greater than or equal to 0. If this constraint is violated, then an IllegalArgument exception should be thrown, as by the following statement: throw new IllegalArgumentException("era < 0"); --------------------------------------------------