Class Watch.Gear
java.lang.Object
it.unimi.di.prog2.h14.member.Watch.Gear
- Enclosing class:
Watch
A gear of a watch.
The gear can "age" in the sense that it keeps track of how many rotations it has done.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionGear(double diameter) Creates a gear with the given diameter and number of teeth. -
Method Summary
-
Field Details
-
diameter
private final double diameterThe diameter of this gear, must be positive. -
rotations
private int rotationsThe number of rotations this gear has done., must be non-negative.
-
-
Constructor Details
-
Gear
public Gear(double diameter) Creates a gear with the given diameter and number of teeth.- Parameters:
diameter- the diameter of this gear.- Throws:
IllegalArgumentException- if diameter is not positive.
-
-
Method Details
-
tick
public void tick()Simulates a tick of this gear, increasing its number of rotations by one. -
rotations
public int rotations()Returns the number of rotations this gear has done.- Returns:
- the number of rotations.
-
toString
-