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 14:30
If the polar bear were taken out of the food chain what would happen to the seal population the seal population would diminish the seal population would grow dramatically the seal population would stay the same the seal population would decrease slightly
Answers: 1
question
Computers and Technology, 24.06.2019 03:30
Explain the importance of html in web page designing in 20 sentences..
Answers: 1
question
Computers and Technology, 24.06.2019 14:30
Alison is having a hard time at work because hee inbox is flooded with emails every day. some of these emails are unsolicited. some of other she don’t need. which action should she take to better manager her emails?
Answers: 1
question
Computers and Technology, 24.06.2019 17:00
Carlos, an algebra teacher, is creating a series of powerpoint presentations to use during class lectures. after writing, formatting, and stylizing the first presentation, he would like to begin writing the next presentation. he plans to insert all-new content, but he wants to have the same formatting and style as in the first one. what would be the most efficient way for carlos to begin creating the new presentation? going under the file tab and opening the first presentation, deleting all content from each page, and adding new content going under the file tab and clicking on new in the left pane, then choosing new from existing going under the design tab and clicking on themes, then selecting the theme that was used for the first template going under the design tab and opening the template that was created for the first presentation
Answers: 2
You know the right answer?
Design a class named Complex for representing complex numbers and the methods add, subtract, multipl...
Questions
question
French, 21.09.2019 08:20
question
Social Studies, 21.09.2019 08:20
Questions on the website: 13722367