Thanks for your help Gloin. I did have to write methods to add, subtract,multiply, and divide complex numbers, but as you suggested all of that was pretty easy. The only reason I'm really struggling with this part is the directions (I feel) are a bit unclear. What I've come up with though is this:
CODE
// These routines convert a complex number into
// a value of the appropriate type; they all throw
// ComplexNumberException if the complex number
// cannot be converted into a real number
public int intValue() {
double value = 0.0;
try {
value = Math.pow(nums[0],2) + Math.pow(nums[1],2);
} catch (ComplexNumberException e1) {
System.err.println("The complex number cannot be converted into a real number.");
} finally {
}
return (int)value;
}
public long longValue() {
double value = 0.0;
try {
value = Math.pow(nums[0],2) + Math.pow(nums[1],2);
} catch (ComplexNumberException e1) {
System.err.println("The complex number cannot be converted into a real number.");
} finally {
}
return (long)value;
}
public float floatValue() {
double value = 0.0;
try {
value = Math.pow(nums[0],2) + Math.pow(nums[1],2);
} catch (ComplexNumberException e1) {
System.err.println("The complex number cannot be converted into a real number.");
} finally {
}
return (float)value;
}
public double doubleValue() {
double value = 0.0;
try {
value = Math.pow(nums[0],2) + Math.pow(nums[1],2);
} catch (ComplexNumberException e1) {
System.err.println("The complex number cannot be converted into a real number.");
} finally {
}
return value;
}
If anyone interprets the directions differently or sees an error please let me know. I really appreciate your help.