forked from deepdalsania/tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConstrct_Demo.java
More file actions
50 lines (42 loc) · 848 Bytes
/
Constrct_Demo.java
File metadata and controls
50 lines (42 loc) · 848 Bytes
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
package oops;
import java.text.DecimalFormat;
public class Constrct_Demo {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Complex c1 = new Complex();
Complex c2 = new Complex(2.34f,3.14f);
Complex c3 = new Complex();
c3 = c3.add(c1,c2);
System.out.print("C1 = ");c1.disp();
System.out.print("C2 = ");c2.disp();
System.out.print("C3 = "); c3.disp();
}
}
class Complex
{
DecimalFormat f = new DecimalFormat("##.00");
float r , i;
Complex(){
r = i = 0;
}
Complex(float a){
r = a;
i = 0;
}
Complex(float a , float b){
r = a;
i = b;
}
Complex add(Complex c1 , Complex c2){
Complex c3 = new Complex();
c3.r = c1.r + c2.r;
c3.i = c1.i + c2.i;
return c3;
}
void disp(){
System.out.println(f.format(r)+ " "+ "+j" + " " +f.format(i));
}
}