Package com.zybooks.dsaj.design
Class Progression
java.lang.Object
com.zybooks.dsaj.design.Progression
- Direct Known Subclasses:
ArithmeticProgression
,FibonacciProgression
,GeometricProgression
Generates a simple progression. By default: 0, 1, 2, ...
-
Field Summary
-
Constructor Summary
ConstructorDescriptionConstructs a progression starting at zero.Progression
(long start) Constructs a progression with given start value. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
advance()
Advances the current value to the next value of the progression.long
Returns the next value of the progression.void
printProgression
(int n) Prints the next n values of the progression, separated by spaces.
-
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
-