我很难使用复数代码的乘法方法。这条线似乎给我带来了最大的麻烦:
public IntegerComplex multiply(IntegerComplex a){
return new IntegerComplex((this.c*a.c - this.d*a.d)+(this.c*a.c + this.d*a.d));
}
我一辈子都想不通;现在我以前从未编码过复数
public class LatticePoint {
private int x;
private int y;
protected double distance;
public LatticePoint()
{
x = 0;
y = 0;
}
public LatticePoint(int x, int y){
setX(x);
setY(y);
}
public void setX(int x){
this.x = x;
}
public int getX()
{
return this.x;
}
public void setY(int y){
this.y = y;
}
public int getY()
{
return this.y;
}
public double distance(LatticePoint p){
LatticePoint q = new LatticePoint(p.x - this.y, p.y - this.x);
return q.distance();
}
public double distance()
{
return Math.sqrt((x*x)+(y*y));
}
public LatticePoint add(LatticePoint p){
return new LatticePoint(this.x + p.x, this.y + p.y);
}
//returns this - p
public LatticePoint sub(LatticePoint p){
return new LatticePoint(this.x - p.x, this.y - p.y);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}
public class IntegerComplex extends LatticePoint {
private int c;
private int d;
public IntegerComplex()
{
super();
}
public IntegerComplex(int c, int d)
{
super.setX(c);
super.setY(d);
}
public int getC(){
return this.c;
}
public int getD(){
return this.d;
}
public IntegerComplex add(IntegerComplex a){
super.add(a);
return a;
}
public double distance(IntegerComplex a){
super.distance(a);
return a.distance();
}
public IntegerComplex multiply(IntegerComplex a){
return new IntegerComplex((this.c*a.c - this.d*a.d)+(this.c*a.c +this.d*a.d));
}
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}