CS 207 Northeastern Illinois University Programming D2L Portal of The Course Project Help with project and please use comments to help understand the material as I look back at it or how you broke the problem down. Northeastern Illinois University
Department of Computer Science
CS 207-2 PROGRAMMING II
BONUS PROJECT
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
+setImag(imag: double): void
+getAngle(): double
+getAngle2(): double
+getRadius(): double
+pow(): double
+conjugate(): Complex
+add(in: Complex): Complex
+subtract(in: Complex): Complex
+multiply(in: Complex): Complex
+divide(in: Complex): Complex
+printComplex(): void
+nextComplex(): Complex
+equals(o: Object): boolean
+toSting(): String
The implementation of the class Complex was provided as a lab.
Northeastern Illinois University
Department of Computer Science
Task 2] Create the class Matrix. The class properties, constructors, and methods are described below. Be
aware that this class does not extend the class Complex. There is a relationship of composition between
the two classes. The created 2D array is always square.
? Matrix
-value: Complex[][]
+Matrix()
+Matrix(n: int)
+getDim(): int
+getReal(): double[][]
+getImag(): double[][]
+getCol(k: int) throws IllegalArgumentException: Complex[]
+getRow(k: int) throws IllegalArgumentException: Complex[]
+getDiag(): Complex[]
+pow(): double
+randomMatrix(size: int): Matrix
+add(m: Matrix): Matrix
+display(): void
(1)
(2)
(3)
(4)
(5)
(6)
(7)
(8)
(9)
(10)
(11)
(12)
(1) A constructor that takes no argument. The constructor creates a 3-by-3 Complex 2D array
referenced by the variable value.
(2) A constructor that takes an integer. The constructor creates an n-by-n Complex 2D array
referenced by the variable value.
(3) This method returns the number of rows in the array referenced by the variable value. Note that
the number of rows is equal to the number of columns.
(4) This method returns the real part of this object as 2D array of type double.
(5) This method returns the imaginary part of this object as 2D array of type double.
(6) This method returns the column of the 2D array referenced by value and whose index is taken as
an argument. The method throws an exception if the taken index k is out of bounds. The method
returns a Complex one-dimensional array.
(7) This method returns the row of the 2D array referenced by value and whose index is taken as an
argument. The method throws an exception if the taken index k is out of bounds. The method
returns a Complex one-dimensional array.
(8) This method returns the diagonal elements of the 2D array referenced by value. The method
returns a Complex one-dimensional array.
(9) This method returns the power sum of the elements of the Complex two-dimensional array
referenced by the variable value of this object.
Northeastern Illinois University
Department of Computer Science
(10)
This method returns a reference to a random size-by-size Complex two-dimensional
array. Use the method nextComplex() from the class Complex to generate a Complex object
whose real and imaginary parts are drawn randomly.
(11)
This method returns a reference to an object from the class Matrix. The returned
reference variable refers to the two-dimensional array resulting from adding this object to the
taken object.
(12)
This method displays this Matrix object. The format is of your choice.
The following is a Test class of the project.
1
2
3
4
5
6
7
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
// methods are invoked not in the order of appearance in the above UML diagram
public class TestMatrix {
public static void main(String[] args) {
// (1)
System.out.println(“—— (1) ——“);
Matrix m0 = new Matrix();
m0.display();
// (2)
System.out.println(“—— (2) ——“);
Matrix m1 = new Matrix(4);
m1.display();
// (3)
System.out.println(“—— (3) ——“);
Matrix m2 = Matrix.randomMatrix(5);
Matrix m3 = Matrix.randomMatrix(5);
m2.display();
m3.display();
// (4)
System.out.println(“—— (4) ——“);
double[][] real = m2.getReal();
Matrix.display(real); // a static method to display 2D array
double[][] imag = m2.getReal();
Matrix.display(imag);
// (5)
System.out.println(“—— (5) ——“);
int k = 1;
try {
Complex[] col = m2.getCol(k);
for (Complex a : col)
a.printComplex();
System.out.println();
} catch (IllegalArgumentException ex) {
Northeastern Illinois University
Department of Computer Science
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
System.out.println(“Invalid column indexn”);
}
// (5)
System.out.println(“—— (6) ——“);
k = 6;
try {
Complex[] row = m2.getRow(k);
for (Complex a : row)
a.printComplex();
System.out.println();
} catch (IllegalArgumentException ex) {
System.out.println(“Invalid column indexn”);
}
// (7)
System.out.println(“—— (7) ——“);
Complex[] diag = m3.getDiag();
for (Complex a : diag)
a.printComplex();
System.out.println();
// (8)
System.out.println(“—— (8) ——“);
System.out.println(“The power of m2 is ” + m2.pow() + “n”);
// (9)
System.out.println(“—— (9) ——“);
Matrix m4 = m2.add(m3);
m4.display();
}
}
—-jGRASP exec: java TestMatrix
—— (1) —–(0.000, 0.000) (0.000, 0.000) (0.000, 0.000)
(0.000, 0.000) (0.000, 0.000) (0.000, 0.000)
(0.000, 0.000) (0.000, 0.000) (0.000, 0.000)
—— (2) —–(0.000, 0.000) (0.000,
(0.000, 0.000) (0.000,
(0.000, 0.000) (0.000,
(0.000, 0.000) (0.000,
0.000)
0.000)
0.000)
0.000)
(0.000,
(0.000,
(0.000,
(0.000,
0.000)
0.000)
0.000)
0.000)
(0.000,
(0.000,
(0.000,
(0.000,
0.000)
0.000)
0.000)
0.000)
—— (3) —–(0.955, 0.610) (0.048,
(0.358, 0.409) (0.660,
(0.924, 0.980) (0.944,
(0.875, 0.461) (0.495,
(0.049, 0.844) (0.805,
0.363)
0.003)
0.642)
0.021)
0.272)
(0.604,
(0.746,
(0.986,
(0.593,
(0.771,
0.936)
0.529)
0.510)
0.587)
0.600)
(0.114,
(0.459,
(0.694,
(0.825,
(0.343,
0.703)
0.416)
0.078)
0.779)
0.542)
(0.199,
(0.486,
(0.053,
(0.002,
(0.650,
0.300)
0.080)
0.500)
0.309)
0.478)
Northeastern Illinois University
Department of Computer Science
(0.176,
(0.505,
(0.828,
(0.495,
(0.511,
0.053)
0.913)
0.259)
0.219)
0.969)
(0.454,
(0.648,
(0.838,
(0.187,
(0.587,
0.141)
0.380)
0.897)
0.802)
0.166)
—— (4) —–0.955 0.048 0.604
0.358 0.660 0.746
0.924 0.944 0.986
0.875 0.495 0.593
0.049 0.805 0.771
0.114
0.459
0.694
0.825
0.343
0.199
0.486
0.053
0.002
0.650
0.955
0.358
0.924
0.875
0.049
0.114
0.459
0.694
0.825
0.343
0.199
0.486
0.053
0.002
0.650
0.048
0.660
0.944
0.495
0.805
0.604
0.746
0.986
0.593
0.771
(0.002,
(0.100,
(0.949,
(0.420,
(0.573,
0.754)
0.243)
0.626)
0.717)
0.270)
(0.492,
(0.422,
(0.985,
(0.722,
(0.041,
0.851)
0.583)
0.495)
0.049)
0.894)
(0.052,
(0.741,
(0.289,
(0.940,
(0.543,
0.826)
0.306)
0.977)
0.696)
0.112)
1.690)
0.772)
1.136)
1.304)
0.870)
(0.606,
(0.880,
(1.679,
(1.547,
(0.384,
1.554)
0.999)
0.573)
0.828)
1.436)
(0.251,
(1.227,
(0.342,
(0.942,
(1.193,
1.126)
0.386)
1.477)
1.005)
0.589)
—— (5) —–(0.048, 0.363)
(0.660, 0.003)
(0.944, 0.642)
(0.495, 0.021)
(0.805, 0.272)
—— (6) —–Invalid row index
—— (7) —–(0.176, 0.053)
(0.648, 0.380)
(0.949, 0.626)
(0.722, 0.049)
(0.543, 0.112)
—— (8) —–The power of m2 is 17.334937810873775
—— (9) —–(1.131, 0.664) (0.502,
(0.863, 1.322) (1.308,
(1.751, 1.239) (1.781,
(1.370, 0.680) (0.681,
(0.559, 1.813) (1.392,
0.504)
0.383)
1.539)
0.823)
0.438)
(0.606,
(0.847,
(1.935,
(1.013,
(1.344,
—-jGRASP: operation complete.
Purchase answer to see full
attachment
Consider the following information, and answer the question below. China and England are international trade…
The CPA is involved in many aspects of accounting and business. Let's discuss some other…
For your initial post, share your earliest memory of a laser. Compare and contrast your…
2. The Ajax Co. just decided to save $1,500 a month for the next five…
How to make an insertion sort to sort an array of c strings using the…
Assume the following Keynesian income-expenditure two-sector model: AD = Cp + Ip Cp = Co…