CS U370 Assignment #6 Section: Clinger Assigned: Friday, 14 November 2008 Corrected: Tuesday, 18 November 2008 (see ! in column 79) Due: Friday, 21 November 2008 The purposes of this assignment are: * To illustrate the Visitor pattern. * To illustrate function objects. * To show how winner-take-all contests tend to magnify small advantages. This assignment is to be done by individual students, not by pairs or teams of students. Collaboration between students is forbidden on this assignment. You are responsible for keeping your code hidden from all other students. You will complete an implementation in Java of the ForEach class specified below. 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 6 and a body that consists of nothing but your ForEach.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, correctness, and efficiency 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, ForEach.java, that implements the ForEach class specified below. You are given two files in /course/csu370wc/Assignments/A6: VotingDistrictVisitor.java Test6.java The VotingDistrictVisitor.java file defines the VotingDistrictVisitor interface, so that file is essential for this assignment. The Test6.java file contains a simple test program; you will need to supplement that test program with further tests. -------------------------------------------------- Specification of the ForEach class. The ForEach class 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 class will be in the default package, and shall define a public class named ForEach. The ForEach class is a client of both the VotingDistrict ADT (as specified in assignment #1) and the SetOfVotingDistrict ADT (as specified in assignment #5). It should therefore work with all possible implementations of those ADTs. It should also work with all function objects that implement the VotingDistrictVisitor interface. The ForEach class shall provide the following public static method: Signature: forEach : VotingDistrictVisitor x SetOfVotingDistrict -> Informal specification: If s.isEmptySet(), then ForEach.forEach(v, s) does nothing. Otherwise let d = s.choose() and s2 = s.without(d). ForEach.forEach(v, s) first calls v's visit method on d, and then behaves as though it had called itself recursively on v and s2. That is, ForEach.forEach(v, s) behaves like this: v.visit(d); ForEach.forEach(v, s2); --------------------------------------------------