import java.util.Scanner;
import java.lang.Math;
public class Complex {
double l,v;
public Complex(){
this.l=0;
this.b=0;
}
public Complex(double l,double v){
this.l=l;
this.v=v;
}
public void setReal(double l){
this.l=l;
}
public void setImage(double v){
this.v=v;
}
public double getReal() {
return this.l;
}
public double getImage() {
return this.v;
}
public static Complex multiply(Complex x, Complex y){
Complex temp = new Complex();
temp.l=x.ly.l+x.vy.v;
temp.v=x.ly.v+x.vy.l;
return temp;
}
public static Complex add(Complex x, Complex y)
{
Complex temp =new Complex();
temp.l=x.l+y.l;
temp.v =x.v +y.v;
return temp;
}
public static Complex delete(Complex x, Complex y)
{
Complex temp = new Complex();
temp.l = x.l - y.l;
temp.v = x.v - y.v;
return temp;
}
public static Complex divide(Complex x, Complex y)
{
Complex temp = new Complex();
temp.l=(x.ly.l+x.vy.v)/(y.ly.l+y.vy.v);
temp.v =(x.vy.l-x.ly.v)/(y.ly.l+y.vy.v);
return temp;
}
public static double qumo(Complex x)
{
double Qumo;
Qumo = Math.sqrt(x.lx.l+x.vx.v);
return Qumo;
}
public static boolean judge(Complex x,Complex y)
{
return x.l == y.r && x.v == y.v;
}
public String toString() { //将一个复数显示为字符串
return this.l + " + " + this.v + "i";
}
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
double real1 , image1 , real2 , image2,mo1,mo2;
System.out.println("请输入第一个复数的实部和虚部:");
real1 = scanner.nextDouble();
image1 = scanner.nextDouble();
System.out.println("\n请输入第二个复数的实部和虚部:");
real2 = scanner.nextDouble();
image2 = scanner.nextDouble();
Complex c1 = new Complex(real1 , image1);
Complex c2 = new Complex(real2 , image2);
mo1 = qumo(c1);
mo2 = qumo(c2);
System.out.println("\n加为:");
System.out.println(c1.toString() + " + " + c2.toString() + " = " + add(c1,c2).toString());
System.out.println("\n减为:");
System.out.println(c1.toString() + " - " + c2.toString() + " = " + delete(c1,c2).toString());
System.out.println("\n乘为:");
System.out.println(c1.toString() + " * " + c2.toString() + " = " + multiply(c1,c2).toString());
System.out.println("\n除:");
System.out.println(c1.toString()+ " / " + c2.toString() + " = " + divide(c1,c2).toString());
System.out.println("\n模长:");
System.out.println(mo1+","+mo2);
System.out.println("\是否相等:");
System.out.println(judge(c1,c2));
}
}