Question: EGR 140: Computer Programming Assignment # 13 : Write an error-free Java program to do the following things. Write a class called Complex. The class
EGR 140: Computer Programming
Assignment # 13:
Write an error-free Java program to do the following things.
Write a class called Complex. The class has two private data members which correspond to the real and imaginary parts of a complex number.
The class Complex should have several (methods) functions: set the values, display the number in real/imaginary (re + j*im) format, and display the number in polar (r, theta) format.
The main program should declare two objects of type Complex. It should set the first object to 4 + j3 and the second object to 1.5-j5.5.
The program should set object 2 to the sum of object 1 and object 2. That is, the real component of object 2 should be set to object1.re +object2.re and similarly for the imaginary part of object 2. You should use a method like add() or plus().
The main program should then print object 2 in a polar format (with theta in degrees) and object 1 in Cartesian format. Good programming design is to make your objects and methods general in order to be used in multiple contexts. Thus, write your code so that the println() statements are in the main() module and it calls method(s) for object1 and object2 to access the data.
Output:
MMMThe complex numbers are: MMMobject 2: length = 6.041522986797286 th = -24.443954780416536 MMMobject 1 = 4.0 + i3.0
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
