CS U370 Assignment #4 Section: Clinger Assigned: Friday, 19 October 2006 Due: Friday, 3 November 2006 The purpose of this assignment is: * To translate an algebraic specification of an immutable abstract data type into executable Java code * To review the java.util.Comparator interface * To see how simple selection and sorting algorithms can be specified algebraically * To introduce a non-trivial example that illustrates and motivates future topics You will complete an implementation in Java of the Report ADT 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 4 and a body that consists of nothing but your Report.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 your following the procedure above for submitting your work. Late assignments may be discounted, and very late assignments may be discarded. -------------------------------------------------- Specification of the Report ADT. Report is an immutable abstract data type. In our implementation language, Java, it corresponds to the project.Report class, which is specified below. The Report class shall be implemented in Java, and will be tested using Sun's Java 2 Runtime Environment, Standard Edition, version 5.0. The code for this implementation will be in the project package, and shall define a public class named Report, which provides the following public methods, which are specified below. Signature and Java syntax: // Basic creators, to be located within the Report class. public static Report empty(); public static Report adjoin(Report, Issue); // Derived creators, to be located within the Report class. public static Report select(Report, Comparator, Issue); public static Report sort(Report, Comparator); public static Report insert(Report, Comparator, Issue); // Accessors public static int length(Report); public static Issue first(Report); public static Issue last(Report); public static Report withoutFirst(Report); public static Report withoutLast(Report); // Canonical Methods public String toString(); Specification of behavior: Report.select(Report.empty(), comp, iss0) = Report.empty() Report.select(Report.adjoin(r, issue), comp, iss0) = Report.adjoin(Report.select(r, comp, iss0), issue) if comp.compare(issue, iss0) = 0 Report.select(Report.adjoin(r, issue), comp, iss0) = Report.select(r, comp, iss0) if comp.compare(issue, iss0) != 0 Report.sort(Report.empty(), comp) = Report.empty() Report.sort(Report.adjoin(r, issue), comp) = Report.insert(Report.sort(r, comp), comp, issue) Report.insert(Report.empty(), comp, iss0) = Report.adjoin(Report.empty(), iss0) Report.insert(Report.adjoin(r, issue), comp, iss0) = Report.adjoin(Report.adjoin(r, issue), iss0) if comp.compare(issue, iss0) <= 0 Report.insert(Report.adjoin(r, issue), comp, iss0) = Report.adjoin(Report.insert(r, comp, iss0), issue) if comp.compare(issue, iss0) > 0 Report.length(Report.empty()) = 0 Report.length(Report.adjoin(r, issue)) = Report.length(r) + 1 Report.first(Report.adjoin(r, issue)) = issue if Report.length(r) = 0 Report.first(Report.adjoin(r, issue)) = Report.first(r) if Report.length(r) > 0 Report.last(Report.adjoin(r, issue)) = issue Report.withoutFirst(Report.adjoin(r, issue)) = Report.empty() if Report.length(r) = 0 Report.withoutFirst(Report.adjoin(r, issue)) = Report.adjoin(Report.withoutFirst(r), issue) if Report.length(r) > 0 Report.withoutLast(Report.adjoin(r, issue)) = r Report.empty().toString() = "Report: empty" Report.adjoin(r, issue).toString() = issue.toString() if Report.length(r) = 0 Report.adjoin(r, issue).toString() = r.toString() + "\n" + issue.toString() if Report.length(r) > 0 Note 1: The comparator argument to the select and sort methods is not necessarily consistent with equals. Note 2: The compare method of the comparator argument to the select and sort methods must not have any side effects. --------------------------------------------------