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 15:10
David is in week 3 of his current ashford course and has a paper due by monday night at midnight. he has finished everything but the concluding paragraph. as he boots up his computer to work on it, he sees a flash across the screen and then the screen goes black. he begins to panic as he tries desperately to turn the laptop back on. david should have saved his work on what kind of portable device?
Answers: 2
question
Computers and Technology, 22.06.2019 19:30
When creating a presentation in libre office impress, where does the editing of slides take place? a. the slides panel b. the center panel c. the tasks panel, under the masters pages tab d. the tasks panel, under the layouts tab
Answers: 3
question
Computers and Technology, 23.06.2019 00:00
What engine component is shown in the above figure?
Answers: 1
question
Computers and Technology, 23.06.2019 00:50
Representa os dados de um banco de dados como uma coleç? o de tabelas constituídas por um conjunto de atributos, que definem as propriedades ou características relevantes da entidade que representam. marque a alternativa que representa o modelo descrito no enunciado. escolha uma:
Answers: 3
You know the right answer?
Design a class named Complex for representing complex numbers and the methods add, subtract, multipl...
Questions
question
Biology, 03.02.2021 14:00
question
Mathematics, 03.02.2021 14:00
question
Biology, 03.02.2021 14:00
Questions on the website: 13722361