-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomplex.java
89 lines (64 loc) · 1.37 KB
/
complex.java
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
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
public class Complex {
private double r;
private double i;
static double a1;
static double b1;
static int count = 0;
Complex(double rr, double ii)
{
r = rr;
i = ii;
count++;
}
Complex(){
count++;
}
public static Complex add(Complex c1, Complex c2)
{
a1 = c1.r + c2.r;
b1 = c1.i + c2.i;
if(b1<0)
{
System.out.println(a1 + " " + b1 + "i");
}
else {
System.out.println(a1 + "+" + b1 + "i");
}
return null;
}
public static Complex subtract(Complex c1, Complex c2)
{
a1 = c1.r - c2.r;
b1 = c1.i - c2.i;
if(b1<0)
{
System.out.println(a1 + " " + b1 + "i");
}
else
{
System.out.println(a1 + "+" + b1 + "i");
}
return null;
}
public void show()
{
System.out.println(r + "+" +i + "i");
}
public static void main(String[] args) throws Exception {
Complex c = new Complex(8, 16);
Complex d = new Complex(5, 15);
Complex e = new Complex();
System.out.println("number of object: " +count);
System.out.println("first number");
d.show();
System.out.println("sum");
e = add(c,d);
System.out.println("difference:");
e = subtract (c,d);
Path path = Paths.get("C:\\Users\\vasuj\\eclipse-workspace\\first project\\src\\task");
Files.createDirectories(path);
}
}