subject

Design a class named Complex for representing complex numbers and the methods add, subtract, multiply, divide, abs for performing complex-number operations, and override toString method for returning a string representation for a complex number. The toString method returns a + bi as a string. If b is 0, it simply returns a. Provide three constructors Complex(a, b), Complex(a), and
Complex(). Complex() creates a Complex object for number 0 and
Complex(a) creates a Complex object with 0 for b. Also provide
the getRealPart() and getImaginaryPart() methods for returning
the real and imaginary part of the complex number, respectively.
Your Complex class should also implement the Cloneable
interface.
Write a test program that prompts the user to enter two complex numbers and display the result of their addition, subtraction, multiplication, and division.
Here is the main class. It cannot be changed.
import java. util. Scanner;
public class Test {
public static void main(String[] args) {
Scanner input = new Scanner(System. in);
System. out. print("Enter the first complex number: ");
double a = input. nextDouble();
double b = input. nextDouble();
Complex c1 = new Complex(a, b);
System. out. print("Enter the second complex number: ");
double c = input. nextDouble();
double d = input. nextDouble();
Complex c2 = new Complex(c, d);
System. out. println("(" + c1 + ")" + " + " + "(" + c2 + ")" + " = " + c1.add(c2));
System. out. println("(" + c1 + ")" + " - " + "(" + c2 + ")" + " = " + c1.subtract(c2));
System. out. println("(" + c1 + ")" + " * " + "(" + c2 + ")" + " = " + c1.multiply(c2));
System. out. println("(" + c1 + ")" + " / " + "(" + c2 + ")" + " = " + c1.divide(c2));
System. out. println("|" + c1 + "| = " + c1.abs());
Complex c3 = (Complex)c1.clone();
System. out. println(c1 == c3);
System. out. println(c3.getRealPart());
System. out. println(c3.getImaginaryPart());
}
}

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 08:10
Alook-up table used to convert pixel values to output values on a monitor. essentially, all pixels with a value of 190 or above are shown as white (i.e. 255), and all values with a value of 63 or less are shown as black (i.e. 0). in between the pixels are scaled so that a pixel with a value p is converted to a pixel of value 2/127 −+3969). if a pixel has a value of 170 originally, what value will be used to display the pixel on the monitor? if a value of 110 is used to display the pixel on the monitor, what was the original value of the pixel?
Answers: 1
question
Computers and Technology, 23.06.2019 00:30
Quick pl which one of the following is considered a peripheral? a software b mouse c usb connector d motherboard
Answers: 1
question
Computers and Technology, 23.06.2019 05:00
Acompany is inviting design for its new corporate logo from its users. this is an example of ? a. crowdfunding b. crowdvoting c. crowdsourced design d. crowdtracking
Answers: 3
question
Computers and Technology, 23.06.2019 11:30
In cell h5 enter a formula that will calculate the percentage of attendees that went to the altamonte springs job fair in 2018.
Answers: 1
You know the right answer?
Design a class named Complex for representing complex numbers and the methods add, subtract, multipl...
Questions
question
History, 15.10.2019 02:30
Questions on the website: 13722359