Write a class to represent a complex number of the form a + bi, where i is the imaginary square root of 1. The constructor should accept two doubles as arguments: the real part a and the imaginary part b. Use an assertion in the constructor to ensure that both of these numbers are positive. The methods you must provide are summarized in Figure 1–32. You may want to include others, such as a main() method for testing. One good test is to create the number 3 + 4i and print its magnitude:
This should print 5.0. Hint: The built-in Math class contains static methods sqrt() (to find a square root) and atan() (to find an arctangent).
Figure 1–32
Already registered? Login
Not Account? Sign up
Enter your email address to reset your password
Back to Login? Click here