Package com.zybooks.dsaj.design
Class AbstractProgression
java.lang.Object
com.zybooks.dsaj.design.AbstractProgression
Generates a simple progression. By default: 0, 1, 2, ...
-
Field Summary
Modifier and TypeFieldDescriptionprotected long
The value that will be reported by a call to nextValue(). -
Constructor Summary
ConstructorDescriptionConstructs a progression starting at zero.AbstractProgression
(long start) Constructs a progression with given start value. -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract 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) Utility that prints the next n values of the progression.
-
Field Details
-
current
protected long currentThe value that will be reported by a call to nextValue().
-
-
Constructor Details
-
AbstractProgression
public AbstractProgression()Constructs a progression starting at zero. -
AbstractProgression
public AbstractProgression(long start) Constructs a progression with given start value.- Parameters:
start
- the first value in the progression
-
-
Method Details
-
nextValue
public long nextValue()Returns the next value of the progression.- Returns:
- the next value in the progression
-
printProgression
public void printProgression(int n) Utility that prints the next n values of the progression.- Parameters:
n
- the number of value to print
-
advance
protected abstract void advance()Advances the current value to the next value of the progression.
-