Question: Create a package named Q 2 . Create a new Java class called ComplexNumber as shown in the UML diagram. Specifications for the ComplexNumber Class

Create a package named Q2.
Create a new Java class called ComplexNumber as shown in the UML diagram.
Specifications for the ComplexNumber Class (In combination with the UML):
The constructor without argument will assign zero to all the field values.
The Constructor with parameters: should accept the real and imaginary values
as arguments and assign these values to the fields (real and imaginary).
Define the accessor/getter methods only; no mutator/setter methods are required. The getMagnitude() method is a helper method which will return the magnitude of
Lab Exercise 05 a complex number. Magnitude of a complex number: a+bi =!+!(Use
Math.pow() and Math.sqrt() methods)
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) is tan"# $ (Here, i is a symbol
"# $ %
for the imaginary part of the number. For tan % use Javas Math class
Math.atan2(b, a) that returns the angle in radians, and use Math.toDegrees(x) method to convert the radians to degrees. You can use these two in nested form. See Unit 2, Part 5.(All the trigonometric methods in the Math class return the results in radians, and to get the result in degrees one must use Math.toDegree(x) method)
The displayRecForm() method will display the complex number as shown in the sample output. For example, if the complex number is (a + bi), it should display a + bi with the corresponding a and b values. The i in the display needs to be hard coded as a literal. The displayed result should use up to 2 decimal places.
3. In the same Java package, create a driver class with the name:
ComplexNumberDemoYourFirstName.
Import the Q1.StudentGradesByYourFirstName class at the top so that you can use your myHeader() and myFooter() methods from that class in the same way, you did in your last lab.
This class will contain two public static fields - a Scanner type instantiated field, and an int type field with an initial value 0, and four public-static methods dataEntry(), complexAdder(), complexMultiplier() and main().
a) Specifications for dataEntry() method:
o Theheader:publicstaticComplexNumberdataEntry()
o Oncecalled,insidethemethod,itwillincrementtheintegertypefieldyou
declared. We use it to keep the track of the number of Complex numbers in a
run. You can see in the sample output that it says complex number 1,2 etc. o Thenitwillprompttheusertoentertherealandimaginarypartsofa
complex number. Get those with the help of the Scanner type data field you
already declared in this class.
o Atthispoint,itwilldeclareaComplextNumbertypereferencevariableand
instantiate it with the above values.
o Finally,itwillreturntheaboveinstantiatedreferencevariablebacktothe
calling method.
b) Specifications for complexAdder() method:
o Theheader:
public static ComplexNumber complexAdder (ComplexNumber x,
ComplexNumber y)
o Oncecalled,itwilldeclareanewComplexNumbertypereferencevariableand instantiate it with the added real-term values of x and y, and the added imaginary-term values of x and y.
Note: If there are two complex numbers x = a + bi, and y = c + di, then, x + y =(a + c)+(b + d) i.
Example: if there are two complex number x =5+2i and y =43i, then, x + y =(5+4)+(2-13)i =911i.
o Itwillreturntheaboveinstantiatedreferencevariablebacktothecalling method.
Page 6 of 8
ES1036B - Programming Fundamentals for Engineers
c) Specifications for complexMultiplier() method:
Lab Exercise 05
Note: Run the program three times as per the following cases. The output should appear as the
following Sample Outputs. To test your code with more data-points, use the following website
(the result may vary slightly in the decimal points while you are comparing, and that is fine):
https://www.omnicalculator.com/math/cartesian-to-polar
Run1:
o Theheader:
public static ComplexNumber complexMultiplier (ComplexNumber x, ComplexNumber y)
o Oncecalled,itwilldeclareanewComplexNumbertypereferencevariable and instantiate it with the appropriate values that result from the multiplication of x and y.
Note: If there are two complex numbers x = a + bi, and y = c + di, then, x * y =(ac - bd)+(bc + ad) i
o Itwillreturntheaboveinstantiatedreferencevariablebacktothecalling method.
d) Specifications for the Driver Method:
o CallmyHeader()inthesamewayasyoudidforQ2inyourpreviouslab. o DeclareaComplexNumbertypereferencevariablex.
o CallthedataEntry()methodandassignthereturnedvaluetoxdeclared
above.
o RepeatthesameprocedureforasecondComplexNumbertypereference
variable y.
o Displaythetwocomplexnumbersusingthea+biformasshowninthe
sample output using the displayRecForm() method.
o Declarea3rdcomplexreferencevariablecalledaddRes.
o CallthecomplexAdder()methodwiththereferencevariablesxandyas
arguments, and then assign the returned value to addRes.
o Declarea4thcomplexreferencevariablecalledmulRes.
o CallthecomplexMultiplier()methodwiththereferencevariablesxandy
as arguments, and then assign the returned value to
 Create a package named Q2. Create a new Java class called

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!