Class MyDouble

java.lang.Object
  extended by MyDouble

public class MyDouble
extends java.lang.Object

MyDouble objects represent floating point values.

Author:
Fawzi Emad

Constructor Summary
MyDouble(double d)
          Initializes the new MyDouble object so that it represents the value of the parameter.
MyDouble(MyDouble m)
          Copy Constructor.
 
Method Summary
 MyDouble abs()
          Returns the absolute value of the current object.
 MyDouble add(MyDouble x)
          Returns the sum of the current object and the parameter.
 int compareTo(MyDouble x)
          Compares the current object to the parameter.
 MyDouble divide(MyDouble x)
          Returns the quotient obtained when dividing the current object by the parameter.
 boolean equals(MyDouble x)
          Checks if the current object is equal to the parameter.
 MyDouble multiply(MyDouble x)
          Returns the product of the current object and the parameter.
 MyDouble sqrt()
          Returns a MyDouble representing the square root of the current object.
 MyDouble subtract(MyDouble x)
          Returns the difference obtained by subtracting the parameter from the current object.
 java.lang.String toString()
          YOU MAY NOT CALL THIS METHOD EXCEPT WHILE YOU ARE IMPLEMENTING THE toString METHOD OF THE COMPLEX NUMBER CLASS!! Returns a String representation of the current object.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MyDouble

public MyDouble(double d)
Initializes the new MyDouble object so that it represents the value of the parameter.

Parameters:
d - value to be "wrapped" in the object

MyDouble

public MyDouble(MyDouble m)
Copy Constructor. Initializes the new MyDouble object so that it represents the same value as that of the parameter.

Parameters:
m - existing MyDouble object that is being copied
Method Detail

add

public MyDouble add(MyDouble x)
Returns the sum of the current object and the parameter. Note: This method does not modify the current object.

Parameters:
x - the value that serves as the second operand for the addition
Returns:
a MyDouble object that represents the sum of the current object and the parameter

subtract

public MyDouble subtract(MyDouble x)
Returns the difference obtained by subtracting the parameter from the current object. Note: This method does not modify the current object.

Parameters:
x - the value to be subtracted
Returns:
a MyDouble object that represents the current object minus the parameter

multiply

public MyDouble multiply(MyDouble x)
Returns the product of the current object and the parameter. Note: This method does not modify the current object.

Parameters:
x - the value that serves as the second operand for the multiplication
Returns:
the product of the current object and the parameter

divide

public MyDouble divide(MyDouble x)
Returns the quotient obtained when dividing the current object by the parameter. Note: This method does not modify the current object.

Parameters:
x - the value that serves as the divisor
Returns:
the result of dividing the current object by the parameter

sqrt

public MyDouble sqrt()
Returns a MyDouble representing the square root of the current object. Note: This method does not modify the current object.

Returns:
the square root of the current object

compareTo

public int compareTo(MyDouble x)
Compares the current object to the parameter.

Parameters:
x - the object being compared with the current object
Returns:
a negative value if the current object is less than the parameter, zero if the current object equals the parameter, a positive value if the current object is larger than the parameter. NOTE: Due to the lack of precision in comparing floating point values, in cases where the two values are NEARLY equal, this method will return 0.

equals

public boolean equals(MyDouble x)
Checks if the current object is equal to the parameter.

Parameters:
x - the object being compared for equality with the current object
Returns:
true if the current object is equal to the parameter, false otherwise. NOTE: Due to the lack of precision in comparing floating point values, in cases where the two values are NEARLY equal, this method will return true.

abs

public MyDouble abs()
Returns the absolute value of the current object.

Returns:
a MyDouble representing the absolute value of the current object.

toString

public java.lang.String toString()
YOU MAY NOT CALL THIS METHOD EXCEPT WHILE YOU ARE IMPLEMENTING THE toString METHOD OF THE COMPLEX NUMBER CLASS!! Returns a String representation of the current object.

Overrides:
toString in class java.lang.Object


Web Accessibility