?? mycomplex.java
//Exercise 7.6
public class MyComplex {
//instance variable
private int real;
private int imag;
//constructor
public MyComplex(int real, int imag){
this.real = real;
this.imag = imag;
}
//getter and setter
public int getReal(){
return real;
}
public int getImag(){
return imag;
}
public void setReal(int real){
this.real = real;
}
public void setImag(int imag){
this.imag = imag;
}
//other
public boolean isReal(){
return (imag == 0);
}
public boolean isImag(){
return (real == 0);
}
public boolean equals(int real, int imag){
return (this.real == real && this.imag == imag);
}
public boolean equals(MyComplex another){
return (this.real == another.real && this.imag == another.imag);
}
//x + jy
public String toString(){
return real + " + " + imag +"j";
}
this.real += another.real;
this.imag += another.imag;
return this;
}
public MyComplex multiply(MyComplex another){
this.real = this.real * another.real - this.imag * another.imag;
this.imag = -(this.real *another.imag + this.imag * another.real);
return this;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -