Answered step by step
Verified Expert Solution
Question
1 Approved Answer
java language please please answer in java language Question 1 Create a package named Lab6Q. Follow the parts outlined below: Part A: Add a public
java language please
please answer in java language
Question 1 Create a package named Lab6Q. Follow the parts outlined below: Part A: Add a public class called MyMethod in the Lab6Q package. Just like Math class, this will be your class that will have all your public-static methods, which you will call with the aid of the class name, as you do for Math method calls. Add and define the following public static methods: public static double myPow(double x, int y) - this method will accept a real number x as base and an integer number y as power, and return x). Here instead of using the Math.pow() method you need to define this method (Hint: this method has been solved in the handout) public static double mySin(double x) - this method will accept a real number (in radian value) and return the sin of that real number. Here instead of using Math.sin() method, you will define this method using the following numerical expression: N sinx (-1)" (2n+1) (2n + 1)! NO Where, n and N are integer values anO! - 1 for n - 0, and n! = 1 x 2 x 3 x 4x .........Xn, for n>0. Pick N - 20 (Hint: Similar problem has been solved in Unit 5, slide 78 (brief version). Also, this slide has been discussed in the pre-recorded lecture and during the class-lecture where it has been said that this kind of questions are asked in the exam. Just create a driver method here, and check whether it works or not, sin(Math.PI/6) - 0.50. Do the same for the other methods in this class. public static double myCos(double x) - this method will accept a real number (In radian value) and return the cos of that real number. Here instead of using Math.cos() method, you will define this method using the following numerical expression: (-1)"x2) COSX (2n)! MO Pick N - 20. Once you try the above with Math.pow() method, replace that with your myPowo method and see whether you get the same result or not. public static void header and footer methods - copy these methods from the previous lab and paste those here. Part B: Add a second public class called RecComplexNum in the Lab6Q package, and define this class using the following UML dingram, and associated specifications. This class will hold on to the characteristics of a Complex class in Rectangular/Cartesian form. You can copy paste your ComplexNumber class from the previous lab just by copying from its package to your Lab6Q package in the Intellij IDE environment, then after right clicking on it, select Refractor Rename, and then rename it as RecComplexNum. You need to Part B: Add a second public class called RecComplexNum in the Lab6Q package, and define this class using the following UML diagram, and associated specifications. This class will hold on to the characteristics of a Complex class in Rectangular/Cartesian form. You can copy-paste your ComplexNumber class from the previous lab just by copying from its package to your Lab6Q package in the Intellij IDE environment, then after right clicking on it, select Refractor Rename, and then rename it as RecComplexNum. You need to Page 1 of 6 ES1036B - Programming Fundamentals for Engineers Lab 06 Question modify this class by taking out most of the previous methods and adding couple of methods as outlined below. RecComplexNum -real: double -Imaginary: double +RecComplexNum () +RecComplexNum (re: double, im: double) +getPolarFromRec():PolarComplexNum +displayRecForm():void . Specifications of the RecComplexNum 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 get PolarFromRec helper method will return the polar form of a RecComplexNum tiject, as a PolarComplexNum object (you need to create this class in next step). Inside this method the magnitude and angle of a PolarComplexNum Object will be calculated as follows: o Magnitude of a complex number a+bi - Va2 + b2 - here you are required to use your MyMethod.myPow() method (you just created) and Math.sqrt() method. o The angle of a complex number is a bi-tan- an? Here you will use Math's atan(x) and toDegrees(x) methods. o Once done, you will instantiate a PolarComplexNum object with these two values (magnitude and angle) and return it. The displayRecForm() method will print the RecComplexNum Object with its real and imaginary parts (see the sample-output for an idea). (magnitude and angle) The displayRecForm() method will print the RecComplexNum Object with its real and imaginary parts (see the sample-output for an idea). Part C: : Add a third public dass called PolarComplexNum in the Lab6Q package, and define this class using the following UML diagram, and associated specifications. This class will hold on to the characteristics of a Complex class in Polar form. PolarComplexNum -magnitude: double -angle: double +PolarComplexNum ( +PolarComplexNum (mag: double, ang: double) +getRecFromPolar(): RecComplexNum displayPolarform():void Specifications of the PolarComplexNum Class: The constructor without argument will assign all field values to zero. The constructor with parameter should accept the magnitude and angle value in degree) as arguments, and assign these values to the fields magnitude and angle. Page 2 of 6 ES1036B - Programming Fundamentals for Engineers Lab 06 Question The getReFromPolar O helper method will return the rectangular / Cartesian form of a PolarComplexNum Object, as a RecComplexNum object (you have already created this class in Part B). Inside this method the real and imaginary values of a RecComplexNum Object will be calculated as follows: The real term of a complex number a-bi-magnitude *cos(angle): i.e. if the magnitude is m and angle is 8, then the real term would be m'cose - here you are required to use your MyMethod.my Cos0 method (you just created) and Math.to Radian() method. The imaginary term of a complex number asbi-magnitude"sin(angle): i.e. if the magnitude Is mand angle is then the imaginary term would be m'sine - here you are required to use your MyMethod.my Sin() method (you just created) and Math.toRadian) method. o Once done, you will instantiate a RecComplexNum object with these two values (real and imaginary) and return it. The display Polar Form) method will print the Polar ComplexNum Object with its magnitude and angle parts (see the sample-output for an idea). . Part D Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started