Question: 6.2 Question 2 PART-A Create a package named Q2. Recycle the Q3 from Lab#4. Create a calculator program to perform arithmetic operations on complex numbers.

 6.2 Question 2 PART-A Create a package named Q2. Recycle the
Q3 from Lab#4. Create a calculator program to perform arithmetic operations on
complex numbers. Create a java class named ComplexNumber, as shown in the
UML diagram. Circle -real: double -imaginary: double +ComplexNumber() + ComplexNumber (re: double,

6.2 Question 2 PART-A Create a package named Q2. Recycle the Q3 from Lab#4. Create a calculator program to perform arithmetic operations on complex numbers. Create a java class named ComplexNumber, as shown in the UML diagram. Circle -real: double -imaginary: double +ComplexNumber() + ComplexNumber (re: double, im: double) +getReal(): double +getimaginary(): double +getMagnitude(): double +getAngle(): double +addTwoComplexNumbers(a: ComplexNumber, b: ComplexNumber): ComplexNumber +subtractTwoComplexNumbers(a: ComplexNumber, b: ComplexNumber): ComplexNumber +multiplyTwoComplexNumbers(a: ComplexNumber, b:ComplexNumber): ComplexNumber +divide TwoComplexNumbers(a: ComplexNumber, b:ComplexNumber): ComplexNumber Page 6 of 10 Specifications for the ComplexNumber Class: The constructor without argument will assign all field values to zero. The constructor with parameter should accept the real and imaginary values as arguments, and assign these values to the fields real and imaginary. The accessor/getter method getReal() will return the real value of the complex number. The accessor/getter method getImaginaryo will return the imaginary value of the complex number The getMagnitude() method is a helper method which will return the magnitude of a complex number. Magnitude of a complex number a+bi = Va2 + b2 (Use Math's pow() and sqrt() methods, see Unit 2: slide 139-140 in regular version) The getAngle() method is a helper method which will return the angle of a complex number in degrees. Angle of a complex number a+bi = tan- (Use Math's atan2tyk) atan(x) and toDegrees(x) methods, see Unit 2: slide 140 in regular version. All the trigonometric methods in Math Class returns the result in radians, and to get the result in degrees one has to use toDegree) method) The addTwoComplex Numbers() method will accept two Complex Number type reference variables as arguments, and after adding these two complex numbers, it will return a ComplexNumber type reference variable. (Hint: Review slide numbers 76 and 84, Unit 4 (regular version) The subtractTwoComplexNumbers() method will accept two Complex Number type reference variables as arguments (For example x and y), subtract the two (i.c. X-y), and will return a ComplexNumber type reference variable. The multiplyTwoComplexNumbers() method will accept two Complex Number type reference variables as arguments, and after multiplying these two complex numbers, it will return a Complex Number type reference variable. Formula for multiplication: (a+bi)*(c+di) = (ac - bd) + (bc+ad)i The divide TwoComplex Numbers() method will accept two ComplexNumber type reference variables as arguments(for example x and y), divide the two (i.e.x/y) and will return a Complex Number type reference variable. Formula for division: (a+bi)/(c+di) = (ac+bd)/k+ (bc-ad)k i where k = c + Specifications for the Driver Class: In the same Java package, create a new driver class with the name ComplexNumberDemo Your FirstName. If your first name is Quazi, the name of this class should be complexNumberDemoQuazi. This class will contain three public static methods: your driver method, header and footer methods and another public static method called convertRectangular TopolarFrom(). Define the rectangular ToPolar From() method as a public static void method which will accept only one ComplexNumber type reference variable as an argument, and then print the polar form of that complex number with the help of the helper methods getMagnitude() and getAngle). This Complex Number object, that you need to pass, can be any object such as A or B. See the sample output before implementing this method. From inside the driver method do the following: a. Call your header method and print the required info. b. Declare two ComplexNumber type reference variables. c. Ask the user to enter the real and imaginary numbers for the first complex number, and get those inputs with the help of a Scanner reference variable. d. Instantiate the first ComplexNumber type reference variable. e. Repeat steps c) and d) for the second one. f. Declare a third ComplexNumber type reference variable and instantiate with the no argument constructor. Use this variable to store your resultant Complex Number value from addition, subtraction, multiplication, or division operation. g. Print a statement to ask the user to select the calculation they would like to perform. Display a menu for addition, subtraction, multiplication, division and Rectangular to Polar to the user. (see the sample output before implementing this part) h. Take user input and perform the right calculation as directed by the user. You must use switch statements to make a decision here. i. Using printf() method print the results as outlined in the sample output. Please note that the polar form for the complex number will be printed from the rectangularToPolar From() method using printf) statement up to two decimal places. j. Call the footer method and end the program. Sample output Run 1: Your Full Name Lab #?, Question #2 YourFirstName's complex-number adder: Calculator for complex numbers: Enter the real part of the first number: 3.52 Enter the imaginary part of the first number: 7.20 Enter the real part of the second number: 8.11 Enter the imaginary part of the second number: -9.31 You entered the following complex numbers: A = 3.52 + 7.20 B = 8.11 - 9.311 What calculation would you like to perform? 1) Addition (A+B) 2) Subtraction (A-B) 3) Multiplication (A*B) 4) Division (A/B) 5) Rectangular to Polar (A/B) Enter choice here: 2 Here is the result: A - B = -4.59 + 16.51i *** Goodbye from yourFullName Run 2: Your Full Name Lab #?, Question #? YourFirstName's complex-number adder: Calculator for complex numbers: Enter the real part of the first number: 3.52 Enter the imaginary part of the first number: 7.20 Enter the real part of the second number: 8.11 Enter the imaginary part of the second number: -9.31 You entered the following complex numbers: A = 3.52 + 7.20 B = 8.11. 9.311 What calculation would you like to perform? 1. Addition (A+B) 2. Subtraction (A-B) 3. Multiplication (A*B) 4. Division (A/B) 5. Rectangular to Polar 6A/B) Enter choice here: 5 Which Complex number do you want to convert to polar form? Enter your choice (A or B): B Here is the result: -4,59 +16.511 - Magnitude:-17-14 and Angle: 74.46 degrees 8.11 - 9.311 = Magnitude: 12.25 and Angle: -48.94 degrees

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!