*13.17(數學:Complex類)設計一個名為Complex的類來表示複數以及完成複數運算的add、substract、,ultiply、divide和abs方法,並且重寫toString方法以返回一個表示複數的字串。方法toString返回字串a+bi。如果b是0,那麼他返回a。Complex類還需要實現Cloneable和Comparable。使用他們的絕對值來比較兩個複數。 提供三個構造方法Complex(a,b)、Complex(a)和Complex()。COmplex()為數字0建立Complex物件,而Complex(a)建立一個b為0的Complex物件。還提供getRealPart()和getImageinaryPart()方法以分別返回複數的實部和虛部。 繪製UML類圖並實現該類。編寫一個測試程式,提示使用者輸入兩個複數,然後顯示他們做加、減、乘、除之後的結果。下面是一個執行示例: Enter the first complex number: 3.5 5.5 Enter the second complex number: -3.5 1 (3.5 + 5.5 i ) + (-3.5 + 1.0 i ) = 0.0 + 6.5 i (3.5 + 5.5 i ) - (-3.5 + 1.0 i ) = 7.0 + 4.5 i (3.5 + 5.5 i ) * (-3.5 + 1.0 i ) = -17.75 + -15.75 i (3.5 + 5.5 i ) / (-3.5 + 1.0 i ) = -0.5094339622641509 + -1.7169811320754718 i *13.17(Math:Complex class)A class named complex is designed to represent complex number and add, substract, multiply, divide and ABS methods to complete complex operation, and override toString method to return a string representing complex number. Method toString returns the string a + bi. If B is 0, then he returns a. The complex class also needs to implement clonable and comparable. Use their absolute values to compare two complex numbers. Three construction methods, complex (a, b), complex (a) and complex(), are provided. Complex() creates a complex object for the number 0, while complex (a) creates a complex object with B = 0. Getrealpart() and getimagenarypart() methods are also provided to return the real and imaginary parts of a complex number, respectively. Draw UML class diagram and implement the class. Write a test program, prompt the user to enter two complex numbers, and then display their results after adding, subtracting, multiplying and dividing. Here is a running example: Enter the first complex number: 3.5 5.5 Enter the second complex number: -3.5 1 (3.5 + 5.5 i ) + (-3.5 + 1.0 i ) = 0.0 + 6.5 i (3.5 + 5.5 i ) - (-3.5 + 1.0 i ) = 7.0 + 4.5 i (3.5 + 5.5 i ) * (-3.5 + 1.0 i ) = -17.75 + -15.75 i (3.5 + 5.5 i ) / (-3.5 + 1.0 i ) = -0.5094339622641509 + -1.7169811320754718 i
Enter the first complex number:3.55.5
Enter the second complex number:-3.51(3.5+5.5 i )+(-3.5+1.0 i )=0.0+6.5 i
(3.5+5.5 i )-(-3.5+1.0 i )=7.0+4.5 i
(3.5+5.5 i )*(-3.5+1.0 i )=-17.75+-15.75 i
(3.5+5.5 i )/(-3.5+1.0 i )=-0.5094339622641509+-1.7169811320754718 i
Process finished with exit code 0