Programming Project: The Two-Towers Problem

Two Towers Problem No, not the towers in Middle Earth. Nor the ones in Hanoi. This assignment requires you to define and use Iterators. You will find the necessary background and considerably helpful suggestions and hints in your text, Chapter 8 and especially Section 8.7 Laboratory: The Two-Towers Problem

However, pay attention to the instructions given here as I am superseding several of the requirements. (Remember my suggestions for success -- “follow instructions”.) Even if you perfectly implement the problem as specified in the book, you will lose credit if you do not attend to the modifications to the instructions given below. The SubsetIterator class you write should use generics and generic Vectors. You will actually use a specific type of Vector, perhaps Integer but I'm not saying; however, your SubsetIterator should take a generic Vector and return subsets one at a time.


Follow the instructions given in the text on pages 175-177 except as follows:

  1. Write your class, SubsetIterator, to implement the java.util.Iterator interface instead of extending AbstractIterator. You do not need to implement the Enumeration interface. As indicated in the text, your class should have a constructor that consumes a single Vector (the set of items from which we want subsets) and the resulting SubsetIterator should return, in turn, different subsets of the elements as Vectors. That is, we are using Vectors to represent sets and subsets are sets.
  2. [No changes; follow the instructions. Your reset() method should start your SubsetIterator back at the beginning.]
  3. The hasNext() is required by the Iterator interface. This bit in the text may be worded awkwardly. Simply follow the requirements of the Iterator interface found in the Java API documentation. After a SubsetIterator's next() method has returned the final subet, this hasNext() method should return false. Return true if there are more subsets to process.
  4. This get method can be a protected or private method that is called by your next() method. Hint: it might be a good idea to have this method take an argument that represents the particular subset that is desired for this call. Note: the get method is introduced in the text as part of the AbstractIterator class. Since we are not extending from that, you are free to write your get method to serve your own purposes. If you write it to return a subset based on a given index, it may be handy for a later assignment.
  5. [No changes]
  6. Since you are implementing the Iterator interface instead of extending the abstract class mentioned by the author, you will need to implement the remove() method. However, as with the PRNG class that you wrote earlier, this need only throw an UnsupportedOperationException.

Non-optional bonus work

I want all of you to at least consider the "Thought Questions" found at the end of the project in your text. I intend to assign either a lab or a homework that is related to the thought questions of this project so I want you to have thought about the issues.

[optional] If you implement (and test and document) the randomSubset() method and use it to generate an approximate solution, you will get extra credit.

Submission instructions:

Do not forget to use the javadoc constructs for your documentation and include the html file produced by the javadoc tool in your final submission. Make sure that you create a folder named with your Westmont email name followed by “HW5”. For example, someone with email address “cjones” would create a folder called “cjonesHW5”. Make sure that inside that folder you have: for both parts of the assignment, java source files and html documentation files (and necessary resources) resulting from javadoc. Finally, either tar or zip the folder so that when we extract it, the folder “<emailname>HW5” will be created. Submit the packaged file for Exercise 5 on Eureka.