Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Java Problem: I provided all the information below. Task 1] Create the class Complex that includes the following properties, constructors, and methods. Most of the
Java Problem: I provided all the information below.
Task 1] Create the class Complex that includes the following properties, constructors, and methods. Most of the methods were previously created in a solved project uploaded to the D2L portal of the course. Complex -real: double -imag: double +Complex() +Complex(real: double, imag: double) +getReal(): double +getImag(): double +setReal(real: double): void +set Imag(imag: double): void +getAngle(): double +getAngle2(): double +getRadius(): double +pow(): double +abs(): double +conjugate(): Complex +add(in: Complex): Complex +add(in: double): Complex + subtract(in: Complex): Complex + subtract(in: double): Complex +multiply(in: Complex): Complex +multiply(in: double): Complex +divide(in: Complex): Complex +divide(in: double): Complex +print Complex(): void +nextComplex(): Complex Task 2Create the class Cvector. The class properties, constructors, and methods are described below.. Cvector -vector: Complex[] +Cvector(size: int) +Cvector(Strings) +Cvector(re: double[], im: double[]) +length(): int +getVector(): Cvector +add(in: Cvector): Cvector +add(in: double[]): Cvector +multiply(in: Cvector): Cvector +divide(in: Cvector): Cvector +pow(): double +abs(): double +conj): Cvector +printCvector(): void +randomVector(size: int): Cvector (1) (2) (3) (4) (5) (6) (8) (9) (10) (11) (12) (13) (14) The data field vector is an array of objects from the class Complex. For example, Cvector v = new Cvector(5); Please keep in mind that v is a reference variable that refers to an object from the class Cvector. An object from the class Cvector contains the reference variable vector which refers to an array of objects from the class Complex. In the following and for the sake brevity, I will refer to vector as an array of Complex objects. (1) A constructor that takes a parameter of type integer. The constructor creates an array of objects from the class Complex referenced by the data field vector. The length of the array is provided as the parameter of the constructor. (2) This constructor takes a String object (a reference variable to an object from the class String). The string contains the real part followed by the imaginary part of each element of the array of Complex objects to be created. Numbers are separated by the space character. The constructor creates an array of Complex objects of appropriate length and parses the double values from the taken string to the created array of Complex objects. The created array is referenced by the data field vector. (3) This constructor creates an array of Complex objects referenced by the data field vector. The real and imaginary parts of the created array are provided in the parameter arrays re and im, respectively. (4) This method returns the data field vector. I suggest you return a reference to a copy rather than to the original data. This prevents alternating the private data field outside the class Cvector. (5) This method returns the number of elements in the array referenced by vector. (6) This method adds this Cvector object to the taken Cvector object and returns the sum as a Cvector object. You can use any of the methods of the class Complex. The operations are performed elementwise. (7) This method multiplies this Cvector object by the taken Cvector object and returns the product as a Cvector object. The multiplication is performed elementwise. (8) This method divides this Cvector object by the taken Cvector object and returns the result of division as a Cvector object. The division is performed elementwise. (9) This method divides this Cvector by the taken array of type double[]. Because the taken array does not contain an imaginary part, the real part of the returned Cvector object is the result of dividing the real part of this Cvector by the parameter array; the imaginary part of the returned Cvector object is the result of dividing the imaginary part of this Cvector by the parameter array. The division is performed elementwise. (10) This method returns the total power of this Cvector object. The total power of a vector is the sum of the power of all its elements. Use the method pow() from the class Complex to compute the power of an object from the class Complex. (11) This method returns the total absolute value of this Cvector object. The total absolute value of a vector is the sum of the absolute values of all its elements. Use the method abs() from the class Complex to compute the power of an object from the class Complex. (12) This method returns the conjugate of this Cvector object as a Cvector object. Refer to the provided code of the Complex class for more details on the conjugate operator. (13) This method displays the data fields of this Cvector object in a format of your choice. This static method creates an instance from the class Cvector. The created instance contains an array of objects from the class Complex of length size (the parameter of the method). The elements of the created array are assigned randomly. You can use any method from the class Complex to assign random values to an object from the class Complex. (14) Bonus To improve the class Cvector, create any additional method you find useful and nontrivial. (3% of extra credit for each created method). The following is a Test class of the project. 1 2 public class Test { public static void main(String[] args) { mN00O // (1) System.out.println(" ------(1)------"); Cvector v1 = new Cvector(3); v1.printCvector(); // (2) System.out.println(" ------(2)------"); String s = "1.5 2.1 3.1 -1.5 9.1 4"; Cvector v2 = new Cvector(s); v2.printCvector(); 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 // (3) System.out.println(" ------(3)------"); double[] re = {2.1, 3.5, -1.01}; double[] im = {5.0, -1, 2.3}; Cvector v3 = new Cvector(re, im); v3.printCvector(); // (4) System.out.println(" ------(4)------"); Cvector v4 = v3.getVector(); v4.printCvector(); // (5) System.out.println(" ------(5)------"); System.out.println(v4.length(); // (6) System.out.println(" ------(6)------"); Cvector v6 = V2.add(v3); v6.printCvector(); // (7) System.out.println(" ------(7)------"); Cvector v7 = V2. mutiply(v3); v7.printCvector(); // (8) System.out.println(" ------(8)------"); double p = v7.pow(); System.out.printf("%.4f ", p); // (9) System.out.println(" ------(9)------"); Cvector v9 = v7.conj(); v9.printCvector(); // (11) 53 54 55 56 System.out.println(" ------(11)------"); Cvector v12 = Cvector.randomVector (5); v12.printCvector(); } 57 } The output of the above program is as follows: ----GRASP exec: java Test (1) ------ (0.000, 0.000) (0.000, 0.000) (0.000, 0.000) (2)---- (1.500, 2.100) (3.100, -1.500) (9.100, 4.000) (3)------ (2.100, 5.000) (3.500, -1.000) (-1.010, 2.300) (4)------ (2.100, 5.000) (3.500,-1.000) (-1.010, 2.300) (5) -- 3 (6) --- (3.600, 7.100) (6.600, -2.500) (8.090, 6.300) ------ (7) ------ (-7.350, 11.910) (9.350, -8.350) (-18.391, 16.890) (8) -- 976.5166 -(9) - (-7.350, -11.910) (9.350, 8.350) (-18.391, -16.890) (11) ----- (0.617, 0.480) (0.704, 0.147) (0.615, 0.579) (0.307, 0.610) (0.257, 0.144) --jGRASP: operation complete
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