Class NaturalNumber3

java.lang.Object
components.naturalnumber.NaturalNumberSecondary
components.naturalnumber.NaturalNumber3
All Implemented Interfaces:
NaturalNumber, NaturalNumberKernel, Standard<NaturalNumber>, Comparable<NaturalNumber>

NaturalNumber represented as a String with implementations of primary methods.
Representation Invariant (concrete invariant of $this):
[all characters of $this.rep are '0' through '9']  and
[$this.rep does not start with '0']
Abstraction Relation (interpretation mapping between $this and this):
this = [if $this.rep = "" then 0
        else the decimal number whose ordinary depiction is $this.rep]
  • Constructor Details

    • NaturalNumber3

      public NaturalNumber3()
      No-argument constructor.
    • NaturalNumber3

      public NaturalNumber3(int i)
      Constructor from int.
      Parameters:
      i - int to initialize from
    • NaturalNumber3

      Constructor from String.
      Parameters:
      s - String to initialize from
    • NaturalNumber3

      Constructor from NaturalNumber.
      Parameters:
      n - NaturalNumber to initialize from
  • Method Details

    • newInstance

      public final NaturalNumber newInstance()
      Description copied from interface: Standard
      Returns a new object with the same dynamic type as this, having an initial value. If the type T has a no-argument constructor, then the value of the new returned object satisfies the contract of the no-argument constructor for T. If T does not have a no-argument constructor, then the value of the new returned object satisfies the contract of the constructor call that was used to initialize this .
      Returns:
      new object "like" this with an initial value
    • clear

      public final void clear()
      Description copied from interface: Standard
      Resets this to an initial value. If the type T has a no-argument constructor, then this satisfies the contract of the no-argument constructor for T. If T does not have a no-argument constructor, then this satisfies the contract of the constructor call that was used to initialize #this.
    • transferFrom

      public final void transferFrom(NaturalNumber source)
      Description copied from interface: Standard
      Sets this to the incoming value of source, and resets source to an initial value; the declaration notwithstanding, the dynamic type of source must be the same as the dynamic type of this. If the type T has a no-argument constructor, then source satisfies the contract of the no-argument constructor for T. If T does not have a no-argument constructor, then source satisfies the contract of the constructor call that was used to initialize #source.
      Parameters:
      source - object whose value is to be transferred
    • multiplyBy10

      public final void multiplyBy10(int k)
      Description copied from interface: NaturalNumberKernel
      Multiplies this by 10 and adds k.
      Parameters:
      k - the int to be added
    • divideBy10

      public final int divideBy10()
      Description copied from interface: NaturalNumberKernel
      Divides this by 10 and reports the remainder.
      Returns:
      the remainder
    • isZero

      public final boolean isZero()
      Description copied from interface: NaturalNumberKernel
      Reports whether this is zero.
      Returns:
      true iff this is zero
    • toString

      public String toString()
      Overrides:
      toString in class NaturalNumberSecondary