package December.dome1214;
public class Complex {
private double real;
private double im;
public Complex() {
}
public Complex(double real,double im) {
System.out.println("有参的构造方法");
this.real=real;
this.im=im;
}
public void setReal(double real) {
this.real=real;
}
public double getReal() {
return real;
}
public void setIm(double im) {
this.im=im;
}
public double getIm() {
return im;
}
public String toString() {
String a= "("+real+"+"+im+"i)";
return a;
}
public Complex addNum(Complex x) {
return new Complex(real+x.real,im+x.im);
}
public void show() {
System.out.println(toString());
}
public void print() {
// TODO Auto-generated method stub
}
}
package December.dome1214;
public class test {
public static void main(String [] args) {
Complex c1=new Complex();
c1.setIm(3);
c1.setReal(2);
c1.show();
}
}