Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

6.3 Question 3 Back drop: Complex Numbers are written in the form a + bi, where a is the real part, b is the imaginary

image text in transcribed
image text in transcribed
image text in transcribed
6.3 Question 3 Back drop: Complex Numbers are written in the form a + bi, where a is the real part, b is the imaginary part and i = V-1. When adding complex numbers, add the real parts together and add the imaginary parts together. If there are two complex number A = 5 + 2i and B = 4 - 3i, then A+ B = (5+4) + (2 - 3)i = 9-i. Create a package named Q3. Consider the UML class diagram below. In your opened Java package, write/define two classes: the first class is called ComplexNumber and has the following specifications: ComplexNumber -real: double -imaginary: double +ComplexNumber() + ComplexNumber (re: double, im: double) +getReal(): double +getimaginary(): double +addTwoComplexNumbers(a: ComplexNumber, b: ComplexNumber): ComplexNumber Page 10 of 12 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 mutator/getter method getReal() will return the real value of the complex number. The mutator/getter method getImaginary() will return the imaginary value of the complex number. The addTwoComplexNumbers() method will accept two ComplexNumber 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) Specifications for the Driver Class: In the same Java package, create a new driver class with the name ComplexNumberDemo YourFirstName. 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, and header and footer methods you have defined earlier. 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. Using this variable call the addTwoComplexNumbers() method and pass the two other ComplexNumber type reference variables, and assign the returned value back to this third variable. g. Using printf() method print the results as outlined in the sample output. h. Call the footer method and end the program. Sample output on next page. Your Full Name Lab #?, Question #? Your FirstName's complex-number adder: Let's add two 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.20i B = 8.11 - 9.31i Here is the result: A + B = 11.63 - 2.11i *** Goodbye from yourFullName ***

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Provide examples of Dimensional Tables.

Answered: 1 week ago