Complex复数类
来源:互联网 发布:淘宝小本生意囤货 编辑:程序博客网 时间:2024/05/22 03:41
public class Complex { private double RealPart;//实部 private double ImagePart;//虚部 /* 定义构造函数 */ public Complex(){ } /* 含参构造方法*/ public Complex(double realPart, double imagePart){ this.RealPart = realPart; this.ImagePart = imagePart; } public void setRealPart(double realPart){ this.RealPart = realPart; } public void setImagePart(double imagePart){ this.ImagePart = imagePart; } public double getRealPart(){ return RealPart; } public double getImagePart(){ return ImagePart; } /* 复数的加法 */ public Complex add(Complex o1){ double realPart1 = this.getRealPart() + o1.getRealPart(); double imagePart1 = this.getImagePart() + o1.getImagePart(); return new Complex(realPart1,imagePart1); } /* 复数的减法 */ public Complex subtract(Complex o1){ double realPart1 = this.getRealPart() - o1.getRealPart(); double imagePart1 = this.getImagePart() - o1.getImagePart(); return new Complex(realPart1,imagePart1); } /* 复数的乘法 */ public Complex multiply(Complex o1){ double realPart1; double imagePart1; if(this.getImagePart() != 0 && o1.getImagePart() != 0){ realPart1 = (this.getRealPart() * o1.getRealPart()) - (this.getImagePart() * o1.getImagePart()); imagePart1 = (this.getRealPart() * o1.getImagePart()) + (this.getImagePart() * o1.getRealPart()); } else{ realPart1 = (this.getRealPart() * o1.getRealPart()); imagePart1 = (this.getRealPart() * o1.getImagePart()) + (this.getImagePart() * o1.getRealPart()); } return new Complex(realPart1,imagePart1); } /* 复数的除法 */ public Complex divide(Complex o1){ double realPart1; double imagePart1; realPart1 = (this.getRealPart() * o1.getRealPart()) + (this.getImagePart() * o1.getImagePart()) / (o1.getImagePart() * o1.getImagePart() + o1.getRealPart() * o1.getRealPart()); imagePart1 = (this.getImagePart() * o1.getRealPart()) - (this.getRealPart() * o1.getImagePart()) / (o1.getImagePart() * o1.getImagePart() + o1.getRealPart() * o1.getRealPart()); return new Complex(realPart1,imagePart1); }
public String toString(){ return this.RealPart+" + "+this.ImagePart+"i"; }
}
阅读全文
0 0
- 设计复数类complex
- 设计复数类Complex
- 设计复数类Complex
- 复数类Complex
- 复数类Complex
- complex复数类
- C++ Complex复数类
- 复数类:class Complex
- 复数类:complex c++
- 复数类 Complex
- Complex复数类
- Complex复数类
- 复数类Complex
- 复数类 complex
- 复数类模板(Complex Class)
- 【C++】c++复数类Complex
- C++中的复数Complex类
- 用java写一个复数类Complex
- Vue + ElementUI 手撸后台管理网站基本框架(二)权限控制
- 【HDU】 1009 FatMouse' Trade
- Tomcat相关
- 【并查集模板】洛谷P3367
- Eclipse基本操作(一)设置Servlet模板、设置Java项目自动进入Tomcat中webapps下
- Complex复数类
- 解析Vin码识别-车架号识别的识别过程
- oracle表分区
- Java中对类中的属性使用set/get方法的意义和用法
- NLPIR_ImportUserDict()函数用户字典导入失败
- 工作日常问题10个
- 1109. Group Photo (25)
- (一)Unity3D 2017 下载安装(配合VS 2017)
- Vue + ElementUI 手撸后台管理网站基本框架(三)登录及系统菜单加载