public class Const extends java.lang.Number implements Arithmetic, java.lang.Comparable
Constructor and Description |
---|
Const()
Creates a new Const with default 0 value
|
Const(double num)
Creates a new real Const for double input.
|
Const(double r,
double i)
Creates a new complex Const for double input.
|
Const(java.lang.Number number)
Creates a new complex Const from a number input.
|
Const(java.lang.String str)
Creates a new Const from the specified string, which should be of the format "1.0", or "1.0 + 1.0i" for complex
numbers.
|
Modifier and Type | Method and Description |
---|---|
Arithmetic |
add(java.lang.Object obj)
Adds this object and the given number
|
int |
compareTo(java.lang.Object num)
Compares this object with the specified object for order.
|
Arithmetic |
divide(java.lang.Object obj)
Divides this object by the given object
|
double |
doubleValue()
Returns the value of the specified number as a
double . |
boolean |
equals(java.lang.Object num)
Returns true if the specified Object has the same value as the Const (the Object must be an instance of
number).
|
float |
floatValue()
Returns the value of the specified number as a
float . |
double |
getImag() |
double |
getReal() |
int |
intValue()
Returns the value of the specified number as an
int . |
boolean |
isCompatible(java.lang.Object obj)
Tests that the given object is a Const.
|
boolean |
isComplex() |
long |
longValue()
Returns the value of the specified number as a
long . |
Arithmetic |
multiply(java.lang.Object obj)
Multiplies this objectand the give number
|
void |
setComplex(double r,
double i)
Set the real part and imaginary parts to the given double inputs.
|
void |
setImag(double i)
Set the imaginary part to the given double.
|
void |
setReal(double r)
Set the real part to the given double.
|
Arithmetic |
subtract(java.lang.Object obj)
Subtracts the number from this object
|
java.lang.String |
toString() |
public Const()
public Const(double num)
num
- the double value.public Const(java.lang.Number number)
number
- the number value.public Const(java.lang.String str) throws java.lang.NumberFormatException
str
- the const stringjava.lang.NumberFormatException
public Const(double r, double i)
r
- the real double value.i
- the imaginary double value.public boolean isComplex()
public double getReal()
public double getImag()
public void setReal(double r)
public void setImag(double i)
public void setComplex(double r, double i)
public boolean isCompatible(java.lang.Object obj)
isCompatible
in interface Arithmetic
obj
- The data object to be compared with the current onepublic boolean equals(java.lang.Object num)
equals
in interface Arithmetic
equals
in class java.lang.Object
num
- The object to be testedpublic int compareTo(java.lang.Object num)
compareTo
in interface java.lang.Comparable
public Arithmetic add(java.lang.Object obj) throws java.lang.ClassCastException
add
in interface Arithmetic
obj
- the object containing the number for the arithmeticjava.lang.ClassCastException
- if addition with the specified object is not validpublic Arithmetic subtract(java.lang.Object obj) throws java.lang.ClassCastException
subtract
in interface Arithmetic
obj
- the object containing the number for the arithmeticjava.lang.ClassCastException
- if subtraction with the specified object is not validpublic Arithmetic multiply(java.lang.Object obj) throws java.lang.ClassCastException
multiply
in interface Arithmetic
obj
- the object containing the number for the arithmeticjava.lang.ClassCastException
- if multiplication with the specified object is not validpublic Arithmetic divide(java.lang.Object obj) throws java.lang.ClassCastException
divide
in interface Arithmetic
obj
- the object containing the number for the arithmeticjava.lang.ClassCastException
- if division with the specified object is not validpublic int intValue()
int
. This may involve rounding or truncation.intValue
in class java.lang.Number
int
.public long longValue()
long
. This may involve rounding or truncation.longValue
in class java.lang.Number
long
.public float floatValue()
float
. This may involve rounding.floatValue
in class java.lang.Number
float
.public double doubleValue()
double
. This may involve rounding.doubleValue
in class java.lang.Number
double
.public java.lang.String toString()
toString
in class java.lang.Object