Computer Science 501
Data Stuctures and Algorithm Analysis
Fall 2013, The College of Saint Rose
This week's assignment is the laboratory at the end of Chapter 8 in Bailey. You will gain experience writing your own generally-useful Iterator class and use it to solve an interesting problem.
Notes and Hints
When you implement your SubsetIterator that extends AbstractIterator, be sure to import structure5.* and java.util.Iterator at the top of your file. Also remember that your SubsetIterator should use generic types. It is far from obvious how to accomplish this, so here is what your class header should look like for the SubsetIterator:
public class SubsetIterator<E,T extends Vector<E>> extends AbstractIterator<T>
During the implementation of your SubsetIterator's get and next methods, you will need to create a Vector<E> and return it as a T to satisfy the required return types specified by AbstractIterator<T> for those methods. Java's syntax for this is again not entirely obvious. This should work:
T subset = (T)new Vector<E>();
For testing, write a main method of your SubsetIterator that creates a Vector<Integer> with the Integers from 0 through 7, creates a SubsetIterator<Integer,Vector<Integer>> with this Vector<Integer>, and then prints out all subsets returned and a count of the subsets returned. Make sure you end up with 256 subsets printed. Please leave this main method in your program when you submit.
Write the main method to solve the two towers problem in a separate class called TwoTowers, proceeding as specified in the lab description in the text.
Thought Questions
In a plain-text file named README, write your answers to the following thought questions.
Before 6:00 PM, Wednesday, October 30, 2013, submit your Java program for grading. There are two things you need to do to complete the submission: (i) upload a copy of your tar or zip file (for your program, please include .java files only, no .class files) using Submission Box under assignment "TwoTowers", and (ii) print and turn in a hard copy of your program.
Don't forget to check your programs for compliance with the Style Guide for CSC 501 Programs
Grading
This lab assignment is graded out of 30 points.
Grading Breakdown | |
Program design and style | 2 points |
Program documentation | 4 points |
Program correctness: SubsetIterator | 8 points |
Program correctness: TwoTowers | 6 points |
Thought questions | 10 points |