Skip to content

Commit 223ef85

Browse files
Queue Operation of Complex Number
1 parent 9ae569d commit 223ef85

File tree

9 files changed

+193
-0
lines changed

9 files changed

+193
-0
lines changed

Cmplx/.classpath

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" path="src"/>
4+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
5+
<classpathentry kind="output" path="bin"/>
6+
</classpath>

Cmplx/.project

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>Cmplx</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
</buildSpec>
14+
<natures>
15+
<nature>org.eclipse.jdt.core.javanature</nature>
16+
</natures>
17+
</projectDescription>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
eclipse.preferences.version=1
2+
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
4+
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
5+
org.eclipse.jdt.core.compiler.compliance=1.8
6+
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
7+
org.eclipse.jdt.core.compiler.debug.localVariable=generate
8+
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
9+
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
10+
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
11+
org.eclipse.jdt.core.compiler.source=1.8

Cmplx/bin/ComplexNumber.class

1.82 KB
Binary file not shown.

Cmplx/bin/ComplexQ.class

938 Bytes
Binary file not shown.

Cmplx/bin/TestClass.class

1.28 KB
Binary file not shown.

Cmplx/src/ComplexNumber.java

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import java.util.Scanner;
2+
import java.lang.Math.*;
3+
4+
public class ComplexNumber {
5+
static Scanner sc = new Scanner(System.in);
6+
7+
private double real;
8+
private double img;
9+
private double mag;
10+
private double theta;
11+
public ComplexNumber(){}
12+
13+
public ComplexNumber(double rl, double im){
14+
real = rl;
15+
img = im;
16+
mag = Math.sqrt(real*real + img*img);
17+
theta = Math.toDegrees(Math.atan(img/real));
18+
}
19+
// Addition
20+
public ComplexNumber add(ComplexNumber Z){
21+
ComplexNumber R = new ComplexNumber(real + Z.real, img + Z.img);
22+
return R;
23+
}
24+
// Subtraction
25+
public ComplexNumber sub(ComplexNumber Z){
26+
ComplexNumber R = new ComplexNumber(real - Z.real, img - Z.img);
27+
return R;
28+
}
29+
/**
30+
public double magnitude(){
31+
return Math.sqrt(real*real + img*img);
32+
}
33+
public double argument(){
34+
return Math.toDegrees(Math.atan(img/real));
35+
}
36+
*/
37+
38+
public void printComplexNumber(){
39+
prl(real + " + " + img + " i ");
40+
prl("Magnitude : " + mag + " && Arguments: " + theta);
41+
}
42+
43+
/**
44+
public static void main(String[] args) {
45+
// TODO Auto-generated method stub
46+
// prl("Hello World");
47+
48+
ComplexNumber c1 = new ComplexNumber(12.0,10.5);
49+
ComplexNumber c2 = new ComplexNumber(15.5,10.5);
50+
ComplexNumber c3 = new ComplexNumber(12.0,20.5);
51+
c1.printComplexNumber();
52+
c2.printComplexNumber();
53+
c3.printComplexNumber();
54+
//prl(c1.magnitude()+ " " + c1.argument());
55+
ComplexNumber R1 = c1.add(c2);
56+
ComplexNumber R2 = R1.sub(c1);
57+
58+
R1.printComplexNumber();
59+
R2.printComplexNumber();
60+
c2.printComplexNumber();
61+
62+
}
63+
*/
64+
65+
static void prl(Object anyObject) {
66+
System.out.println(anyObject);
67+
}
68+
69+
}

Cmplx/src/ComplexQ.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
2+
public class ComplexQ {
3+
private ComplexNumber[] Queue;
4+
private int rear;
5+
private int front;
6+
// Default Constructor
7+
public ComplexQ() {
8+
Queue = new ComplexNumber[1000];
9+
rear = 0;
10+
front = 0;
11+
}
12+
// Parameter Constructor(Initialize Size Of Queue)
13+
public ComplexQ(int Size) {
14+
Queue = new ComplexNumber[Size];
15+
rear = 0;
16+
front = 0;
17+
}
18+
19+
public void Insert(ComplexNumber itm){
20+
Queue[rear++] = itm;
21+
}
22+
public void Delete(ComplexNumber itm) {
23+
front++;
24+
}
25+
26+
public void showQueue(){
27+
for(int i = front; i< rear; i++){
28+
Queue[i].printComplexNumber();
29+
}
30+
}
31+
32+
33+
// public static void main(String[] args) {
34+
// // TODO Auto-generated method stub
35+
//
36+
// }
37+
38+
}

Cmplx/src/TestClass.java

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
2+
public class TestClass {
3+
ComplexNumber R;
4+
ComplexNumber Z1;
5+
ComplexNumber Z2;
6+
ComplexNumber Z3;
7+
8+
ComplexQ CQ;
9+
10+
public TestClass(){}
11+
12+
public void TestQ() {
13+
CQ = new ComplexQ(5);
14+
Z1 = new ComplexNumber(12.0,10.5);
15+
Z2 = new ComplexNumber(15.5,10.5);
16+
Z3 = new ComplexNumber(12.0,20.5);
17+
CQ.Insert(Z1);
18+
CQ.Insert(Z2);
19+
CQ.Insert(Z3);
20+
CQ.showQueue();
21+
22+
}
23+
24+
public void TestRun(){
25+
Z1 = new ComplexNumber(12.0,10.5);
26+
Z2 = new ComplexNumber(15.5,10.5);
27+
Z3 = new ComplexNumber(12.0,20.5);
28+
29+
//R = Z1.printComplexNumber();
30+
31+
}
32+
33+
public static void main(String[] args) {
34+
// TODO Auto-generated method stub
35+
36+
// Z1 = new ComplexNumber(12.0,10.5);
37+
// Z2 = new ComplexNumber(15.5,10.5);
38+
// Z3 = new ComplexNumber(12.0,20.5);
39+
//
40+
// R = Z1.printComplexNumber();
41+
42+
TestClass T = new TestClass();
43+
T.TestRun();
44+
T.TestQ();
45+
46+
}
47+
48+
static void prl(Object anyObject) {
49+
System.out.println(anyObject);
50+
}
51+
52+
}

0 commit comments

Comments
 (0)