Package org.cis1200

Class ListNumberGenerator

java.lang.Object
org.cis1200.ListNumberGenerator
All Implemented Interfaces:
NumberGenerator

public class ListNumberGenerator extends Object implements NumberGenerator
Produces a deterministic sequence of numbers. This class is implemented for you.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a ListNumberGenerator which generates numbers based off of an array of possible integers.
    Creates a ListNumberGenerator which generates numbers based off of a list of possible integers.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Returns the next integer available in the list.
    int
    next(int bound)
    Returns the next integer available in the list that is less than the specified bound.
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • ListNumberGenerator

      public ListNumberGenerator(List<Integer> list)
      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 interface NumberGenerator
      Parameters:
      bound - - the max value that can be returned by this call to next.
      Returns:
      a number between 0 and bound (inclusive)
    • toString

      public String toString()
      Overrides:
      toString in class Object