Created
January 19, 2017 13:00
-
-
Save mirsahib/a34ec0b34b4cdb1384016a6d92a992ff to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ComplexNo{ | |
private int real; | |
private int img; | |
public void getNo(int a,int b){ | |
this.real=a; | |
this.img=b; | |
System.out.println("Real number is: "+this.real+"\nImaginary number is: "+this.img+"i"); | |
} | |
public void getNo(ComplexNo a){ | |
this.real=a.real; | |
this.img=a.img; | |
} | |
public ComplexNo operatorPlus(ComplexNo x){ | |
ComplexNo temp = new ComplexNo(); | |
temp.real=this.real+x.real; | |
temp.img=this.img+x.img; | |
return temp; | |
} | |
public void display(){ | |
if(this.img>0){ | |
System.out.println("The complex no is:"+this.real+"+"+this.img+"i"); | |
}else{ | |
System.out.println("The complex no is:"+this.real+"-"+Math.abs(this.img)+"i"); | |
} | |
} | |
} | |
public class TestComplexNo { | |
public static void main(String[] args) { | |
ComplexNo c1 = new ComplexNo(); | |
ComplexNo c2 = new ComplexNo(); | |
ComplexNo c3 = new ComplexNo(); | |
ComplexNo c4 = new ComplexNo(); | |
c1.getNo(12, -3); | |
c2.getNo(4, 3); | |
c3.getNo(3,4); | |
c4.getNo(c1.operatorPlus(c2).operatorPlus(c3)); | |
c4.display(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment