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
Why Choose Us
Top quality papers
We always make sure that writers follow all your instructions precisely. You can choose your academic level: high school, college/university or professional, and we will assign a writer who has a respective degree.
Professional academic writers
We have hired a team of professional writers experienced in academic and business writing. Most of them are native speakers and PhD holders able to take care of any assignment you need help with.
Free revisions
If you feel that we missed something, send the order for a free revision. You will have 10 days to send the order for revision after you receive the final paper. You can either do it on your own after signing in to your personal account or by contacting our support.
On-time delivery
All papers are always delivered on time. In case we need more time to master your paper, we may contact you regarding the deadline extension. In case you cannot provide us with more time, a 100% refund is guaranteed.
Original & confidential
We use several checkers to make sure that all papers you receive are plagiarism-free. Our editors carefully go through all in-text citations. We also promise full confidentiality in all our services.
24/7 Customer Support
Our support agents are available 24 hours a day 7 days a week and committed to providing you with the best customer experience. Get in touch whenever you need any assistance.
Try it now!
How it works?
Follow these simple steps to get your paper done
Place your order
Fill in the order form and provide all details of your assignment.
Proceed with the payment
Choose the payment system that suits you most.
Receive the final file
Once your paper is ready, we will email it to you.
Our Services
No need to work on your paper at night. Sleep tight, we will cover your back. We offer all kinds of writing services.
Essays
You are welcome to choose your academic level and the type of your paper. Our academic experts will gladly help you with essays, case studies, research papers and other assignments.
Admissions
Admission help & business writing
You can be positive that we will be here 24/7 to help you get accepted to the Master’s program at the TOP-universities or help you get a well-paid position.
Reviews
Editing your paper
Our academic writers and editors will help you submit a well-structured and organized paper just on time. We will ensure that your final paper is of the highest quality and absolutely free of mistakes.
Reviews
Revising your paper
Our academic writers and editors will help you with unlimited number of revisions in case you need any customization of your academic papers