Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change.If you are satisfied with the solution, please rate the answer.Thanks
=========================================================================================
public class Complex {
final private double x, y;
public Complex(double x, double y) {
this.x = x;
this.y = y;
}
public Complex minus(Complex z) {
return new Complex(x - z.x, y - z.y);
}
public String toString() {
if (y == 0) {
return "" + x;
}
if (y > 0) {
return "" + x + " + " + y+"j";
}
// otherwise y<0.
return "" + x + " - " + (-y)+"j";
}
public double getX() {
return x;
}
public double getY() {
return y;
}
public void displayInPolar() {
// calculate radius
double radius = Math.sqrt(x * x + y * y);
// convert from radian to degrees
double degrees = Math.asin(y / radius)*57.2958;
System.out.println("Length = " + radius + " th = " + degrees);
}
public static void main(String[] args) {
Complex object1 = new Complex(3,2.5);
Complex object2 = new Complex(2.7,-6.8);
System.out.println(object1);
System.out.println(object2);
object2.displayInPolar();
System.out.println(object1.minus(object2));
}
}
=========================================================================================

thanks a lot !
Write a class called "Complex". The class has two private data members which correspond to the...
Define a class named COMPLEX for complex numbers, which has two private data members of type double (named real and imaginary) and the following public methods: 1- A default constructor which initializes the data members real and imaginary to zeros. 2- A constructor which takes two parameters of type double for initializing the data members real and imaginary. 3- A function "set" which takes two parameters of type double for changing the values of the data members real and imaginary....
Create a class for working with complex numbers. Only 2 private float members are needed, the real part of the complex number and the imaginary part of the complex number. The following methods should be in your class: a. A default constructor that uses default arguments in case no initializers are included in the main. b. Add two complex numbers and store the sum. c. Subtract two complex numbers and store the difference. d. Multiply two complex numbers and store...
C++
//add as many comments as possible
5. A complex number consists of two components: the real component and the imaginary component. An example of a complex number is 2+3i, where 2 is the real component and 3 is the imaginary component of the data. Define a class MyComplexClass. It has two data values of float type: real and imaginary This class has the following member functions A default constructor that assigns 0.0 to both its real and imaginary data...
Create a class called Complex for performing arithmetic with complex numbers. Complex numbers have the form: realPart + imaginaryPart * i where i is √-1 Use double variables to represent the private data of the class. Provide a constructor that enables an object of this class to be initialized when it’s declared. The constructor should contain default values of (1,1) i.e. 1 for the real part and 1 for the imaginary part. Provide public member functions that perform the following...
C++ Complex Class!
Create a class called Complex for performing arithmetic with complex numbers. Write a program to test your class. Complex numbers have the form realPart + imaginaryPart * i where i is Squareroot -1 Use double variables to represent the private data of the class. Provide a constructor that enables an object of this class to be initialized when ifs declared. The constructor should contain default values in case no initializers are provided. Provide public member functions that...
Create the header file named “Complex.h” that contains the following class: The class Complex represents a complex number which is a number of the form a + bi where a and b are real numbers and i2 = −1. The class should contain: Private double field named real. Private double field named imaginary. Public default constructor that assigns 1 to real and 0 to imaginary. Public overloaded constructor that takes a double as a parameter named real. It assigns real...
C++
Create a class called Complex for performing arithmetic with complex numbers. Write a program to test your class. Complex numbers have the form realPart + j imaginaryPart Use double variables to represent the private data of the class. Provide a constructor that enables an object of this class to be initialized when it is declared. The constructor should contain default values in case no initializers are provided. Provide public member functions that perform the following tasks: Adding two Complex...
C++ CLASS FOR DEFINING COMPLEX NUMBERS (READ BELOW) Write a C++ defining a class for complex numbers. A complex number is a number of the form: a + b ∗ i , where, for our purposes, a and b are numbers of type double, and i is a number that represents the quantity √ −1. You should represent a complex number here as two values of type double. You should name the variables real and imaginary. You can call the...
C++ Addition of Complex Numbers Background Knowledge A complex number can be written in the format of , where and are real numbers. is the imaginary unit with the property of . is called the real part of the complex number and is called the imaginary part of the complex number. The addition of two complex numbers will generate a new complex number. The addition is done by adding the real parts together (the result's real part) and adding the...
USING C++, write a simple class defining complex numbers USING the FRIEND function (READ BELOW) Write a C++ defining a class for complex numbers. A complex number is a number of the form: a + b ∗ i , where, for our purposes, a and b are numbers of type double, and i is a number that represents the quantity √−1. You should represent a complex number here as two values of type double. You should name the variables real...