Package com.zybooks.dsaj.design
Class GeometricProgression
java.lang.Object
com.zybooks.dsaj.design.Progression
com.zybooks.dsaj.design.GeometricProgression
A class producing a geometric progression of the form start, start*factor, start*factor*factor, ...
-
Field Summary
Fields inherited from class com.zybooks.dsaj.design.Progression
current
-
Constructor Summary
ConstructorDescriptionConstructs progression 1, 2, 4, 8, 16, ...GeometricProgression
(long b) Constructs progression 1, b, b^2, b^3, b^4, ...GeometricProgression
(long b, long start) Constructs geometric progression with arbitrary base and start. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
advance()
Multiplies the current value by the geometric base.Methods inherited from class com.zybooks.dsaj.design.Progression
nextValue, printProgression
-
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 progressionstart
- the first value of the progression
-
-
Method Details
-
advance
protected void advance()Multiplies the current value by the geometric base.- Overrides:
advance
in classProgression
-