Package org.cis1200
Class ListNumberGenerator
java.lang.Object
org.cis1200.ListNumberGenerator
- All Implemented Interfaces:
NumberGenerator
Produces a deterministic sequence of numbers. This class is implemented for you.
-
Constructor Summary
ConstructorsConstructorDescriptionListNumberGenerator
(int[] arr) Creates a ListNumberGenerator which generates numbers based off of an array of possible integers.ListNumberGenerator
(List<Integer> list) Creates a ListNumberGenerator which generates numbers based off of a list of possible integers. -
Method Summary
-
Constructor Details
-
ListNumberGenerator
Creates a ListNumberGenerator which generates numbers based off of a list of possible integers.- Parameters:
list
- - a list of integers to step through and output in the generator.- Throws:
IllegalArgumentException
- - when list is null, of size 0, or when any Integer in the list is null.
-
ListNumberGenerator
public ListNumberGenerator(int[] arr) Creates a ListNumberGenerator which generates numbers based off of an array of possible integers.- Parameters:
arr
- - an array of integers to step through and output in the generator.- Throws:
IllegalArgumentException
- - when arr is null or empty
-
-
Method Details
-
next
public int next()Returns the next integer available in the list. Start over if the last number is reached.- Returns:
- a number from the list.
-
next
public int next(int bound) Returns the next integer available in the list that is less than the specified bound.- Specified by:
next
in interfaceNumberGenerator
- Parameters:
bound
- - the max value that can be returned by this call to next.- Returns:
- a number between 0 and bound (inclusive)
-
toString
-