Class GeometricProgression

java.lang.Object
com.zybooks.dsaj.design.Progression
com.zybooks.dsaj.design.GeometricProgression

public class GeometricProgression extends Progression
A class producing a geometric progression of the form start, start*factor, start*factor*factor, ...
  • Field Details

    • base

      protected long base
  • Constructor Details

    • GeometricProgression

      public GeometricProgression()
      Constructs progression 1, 2, 4, 8, 16, ...
    • GeometricProgression

      public GeometricProgression(long b)
      Constructs progression 1, b, b^2, b^3, b^4, ... for base b.
      Parameters:
      b - the base of the geometric progression
    • GeometricProgression

      public GeometricProgression(long b, long start)
      Constructs geometric progression with arbitrary base and start.
      Parameters:
      b - the base of the geometric progression
      start - the first value of the progression
  • Method Details

    • advance

      protected void advance()
      Multiplies the current value by the geometric base.
      Overrides:
      advance in class Progression