Class Progression

java.lang.Object
com.zybooks.dsaj.design.Progression
Direct Known Subclasses:
ArithmeticProgression, FibonacciProgression, GeometricProgression

public class Progression extends Object
Generates a simple progression. By default: 0, 1, 2, ...
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected long
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a progression starting at zero.
    Progression(long start)
    Constructs a progression with given start value.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    Advances the current value to the next value of the progression.
    long
    Returns the next value of the progression.
    void
    Prints the next n values of the progression, separated by spaces.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • current

      protected long current
  • Constructor Details

    • Progression

      public Progression()
      Constructs a progression starting at zero.
    • Progression

      public Progression(long start)
      Constructs a progression with given start value.
      Parameters:
      start - the first value of the progression
  • Method Details

    • nextValue

      public long nextValue()
      Returns the next value of the progression.
      Returns:
      the next value of the progression
    • advance

      protected void advance()
      Advances the current value to the next value of the progression.
    • printProgression

      public void printProgression(int n)
      Prints the next n values of the progression, separated by spaces.
      Parameters:
      n - number of terms to print