This website is preserved for historical and scholarly reference and is no longer actively maintained.
                         CpSc 210, Section 1
                             Assignment 8 
                             23 June 2000


Due: Friday, June 23 at midnight

Late penalties: 20 points per partial day late.  That is, programs
	turned in after midnight Friday and before midnight Saturday
	will have 20 points deducted for late, programs turned in after
	midnight Saturday and before midnight Sunday will have a total
	of 40 points deducted for late, etc.  Since this assignment 
	uses the Drawing Window, you should give considerable attention
	to getting the assignment in early if you cannot use the
	Drawing Window from a remote location.

Total point value of assignment:  100 points

Late submissions not accepted after: Monday, June 26 at midnight

This assignment is to be done INDIVIDUALLY.



Create a directory, A8, which will contain all parts of this assignment.
(In this assignment the directory A8 will contain a file
named PrimeIterator.java.)  

Assignment:

	Problem 8.3, page 165).  Write an Iterator that returns
	a stream of Integers that are prime.  (Note the type:
	Integer, not int.)

	Your class Primes should implement the Iterator interface
	found on page 157.  Your class header should be:

	     public class PrimeIterator implements Iterator   

	You must import Bailey's structure package to gain access
	to the Iterator interface.                    

	One of your instance variables should be a Vector
	which is initialized with Integer 2 at the zero
	subscript and Integer 3 at the subscript one.  Exactly
	one copy of this Vector should exist at any time
	regardless of the number of instances of class
	PrimeIterator.  (See the List implementation in Java
	Elements for how to create this vector.)

	When nextElement is called, there are two possible actions
	that can be taken to find the next prime for the instance
	of PrimeIterator that issued the call.

	(1)  If the next prime can be found in the vector, that
	value is returned and current incremented, and

	(2)  If the value to which current should be advanced
	has not been calculated (has not been stored in the
	vector), the value that will be returned the next time
	nextElement is called, must be calculated and stored
	in the vector before returning to the calling program.

	For example, the first time nextElement() is called,
	the Integer 2 will be returned and current set to
	reference where the Integer 3 is called.  The next time
	nextElement() is called, the Integer 5 must be calculated
	and stored in the vector before the Integer 3 is returned.
	When you return current will reference the Integer 5.

	You may choose to implement steps (1) and (2) differently
	than described above, but however you do so, the result
	will be that you do not recalculate a prime that has
	already been calculated and you store any new prime that
	you find it necessary to calculate.


Input:  

	Input, if any, should be contained in your test program (main).
	Use the ReadStream class (page 334) that is part of Bailey's
	structure package for any input.

Output:

	Your main method should print your name, the assignment number, 
	and a short description of the assignment.  Use the System.out
	commands.

	Output should be contained in your test program (main).
	Your class will also be tested with other test program(s).

Other requirements:

	Follow the style standards to be found on your instructor's
	web page for CPSC 210.

	Submit your program using the handin command.  There is a link to
	the handin description on your lab page (www.cs.clemson.edu/~lab210).


Grading rubric:

	Required documentation 10 pts.
	Style standards 10 pts.

	The program compiles without error.  10 pts.

    If the program does not compile, no further points will be awarded.

	Exactly one copy of the prime vector is used by all instances of
	PrimeIterator and more than one instance is possible.  10 pts.

	Iterator correctly returns primes (as many as requested by the users)
		40 pts.
	
	Efficiency of algorithms (!)   (Assumes algorithms are correct.)
		20 pts.