Class Watch.Gear

java.lang.Object
it.unimi.di.prog2.h14.member.Watch.Gear
Enclosing class:
Watch

public static class Watch.Gear extends Object
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
    Modifier and Type
    Field
    Description
    private final double
    The diameter of this gear, must be positive.
    private int
    The number of rotations this gear has done., must be non-negative.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Gear(double diameter)
    Creates a gear with the given diameter and number of teeth.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Returns the number of rotations this gear has done.
    void
    Simulates a tick of this gear, increasing its number of rotations by one.
     

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • diameter

      private final double diameter
      The diameter of this gear, must be positive.
    • rotations

      private int rotations
      The 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

      public String toString()
      Overrides:
      toString in class Object