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
FieldsModifier and TypeFieldDescriptionprotected longThe value that will be reported by a call to nextValue(). -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a progression starting at zero.AbstractProgression(long start) Constructs a progression with given start value. -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract voidadvance()Advances the current value to the next value of the progression.longReturns the next value of the progression.voidprintProgression(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.
-