Package components.naturalnumber
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]
-
Field Summary
Fields inherited from interface components.naturalnumber.NaturalNumberKernel
RADIX
-
Constructor Summary
ConstructorDescriptionNo-argument constructor.NaturalNumber3
(int i) Constructor fromint
.Constructor fromNaturalNumber
.Constructor fromString
. -
Method Summary
Modifier and TypeMethodDescriptionfinal void
clear()
Resetsthis
to an initial value.final int
Dividesthis
by 10 and reports the remainder.final boolean
isZero()
Reports whetherthis
is zero.final void
multiplyBy10
(int k) Multipliesthis
by 10 and addsk
.final NaturalNumber
Returns a new object with the same dynamic type asthis
, having an initial value.toString()
final void
transferFrom
(NaturalNumber source) Setsthis
to the incoming value ofsource
, and resetssource
to an initial value; the declaration notwithstanding, the dynamic type ofsource
must be the same as the dynamic type ofthis
.Methods inherited from class components.naturalnumber.NaturalNumberSecondary
add, canConvertToInt, canSetFromString, compareTo, copyFrom, decrement, divide, equals, hashCode, increment, multiply, power, root, setFromInt, setFromString, subtract, toInt
-
Constructor Details
-
NaturalNumber3
public NaturalNumber3()No-argument constructor. -
NaturalNumber3
Constructor fromint
.- Parameters:
i
-int
to initialize from
-
NaturalNumber3
Constructor fromString
.- Parameters:
s
-String
to initialize from
-
NaturalNumber3
Constructor fromNaturalNumber
.- Parameters:
n
-NaturalNumber
to initialize from
-
-
Method Details
-
newInstance
Description copied from interface:Standard
Returns a new object with the same dynamic type asthis
, having an initial value. If the typeT
has a no-argument constructor, then the value of the new returned object satisfies the contract of the no-argument constructor forT
. IfT
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 initializethis
.- Returns:
- new object "like"
this
with an initial value
-
clear
Description copied from interface:Standard
Resetsthis
to an initial value. If the typeT
has a no-argument constructor, thenthis
satisfies the contract of the no-argument constructor forT
. IfT
does not have a no-argument constructor, thenthis
satisfies the contract of the constructor call that was used to initialize#this
. -
transferFrom
Description copied from interface:Standard
Setsthis
to the incoming value ofsource
, and resetssource
to an initial value; the declaration notwithstanding, the dynamic type ofsource
must be the same as the dynamic type ofthis
. If the typeT
has a no-argument constructor, thensource
satisfies the contract of the no-argument constructor forT
. IfT
does not have a no-argument constructor, thensource
satisfies the contract of the constructor call that was used to initialize#source
.- Parameters:
source
- object whose value is to be transferred
-
multiplyBy10
Description copied from interface:NaturalNumberKernel
Multipliesthis
by 10 and addsk
.- Parameters:
k
- theint
to be added
-
divideBy10
Description copied from interface:NaturalNumberKernel
Dividesthis
by 10 and reports the remainder.- Returns:
- the remainder
-
isZero
Description copied from interface:NaturalNumberKernel
Reports whetherthis
is zero.- Returns:
- true iff
this
is zero
-
toString
- Overrides:
toString
in classNaturalNumberSecondary
-