hi everyone. well I have a small problem. Actually, I have an interface (ComplexNum) and a class (ComplexNumb).The end result is to do small calculation with some complex numbers. I have already implemented the interface in the class , but eclipse keeps on telling me that I have to implement one function (which is already present ) in the class.Can you please help me out??
public interface ComplexNum {
public int getReal();
public int getComplex();
public void setReal(int r);
public void setComplex(int c);
public String add();
public String subtract();
public String multiply();
public void display();
}
public class ComplexNumb implements ComplexNum{
private int real;
private int comp;
public ComplexNumb(){
real=0;
comp=0;
}
public ComplexNumb(int rl,int cmp){
real=rl;
comp=cmp;
}
public int getReal(){return real;}
public int getComplex(){return comp;}
public void setReal(int rt){real=rt;}
public void setComplex(int cp){comp=cp;}
public String add (ComplexNumb a, ComplexNumb b){
int x=a.getReal()+ b.getReal();
int y=a.getComplex()+b.getComplex();
//String ys ;
String ys =y + "i" ;
System.out.println( "(" + x + ',' + ys + ')' );
return ( "(" + x + ',' + ys + ')' );
}
public String subtract(ComplexNumb a, ComplexNumb b){
int x=a.getReal()-b.getReal();
int y=a.getComplex()-b.getComplex();
String yst=y +"i";
System.out.println( '(' +x+ ',' + y + ')');
return ( "(" + x + "," + yst + ")" );
}
public String multiply(ComplexNumb a, ComplexNumb b){
int x=a.getReal()*b.getReal() - a.getComplex()*b.getComplex();
int y=a.getReal()*b.getComplex() + a.getComplex()*b.getReal() ;
String ym= y + "i";
System.out.println( "(" + x + "," + ym + ")");
return ( "(" + x + "," + ym + ")");
}
public void display(ComplexNumb a, ComplexNumb b){
String f=add(a,b);
String g=subtract(a,b);
String h=multiply(a,b);
System.out.println(f);
System.out.println(g);
System.out.println(h);
}
}