急!!!!!!高手指教(JAVA)
3、设计复数类(ComplexNumber),成员变量包括实部(real)和虚部(imaginary),成员方法包括实现复数加法(add(ComplexNumberobj...
3、设计复数类(ComplexNumber),成员变量包括实部(real )和虚部(imaginary),成员方法包括实现复数加法(add(ComplexNumber obj))、减法(sub(ComplexNumber obj))、乘法(multiply(ComplexNumber obj)) 、成串(toString())等操作。
(a+bi)+(c+di)=(a+c)+(b+d)i,
(a+bi)-(c+di)=(a-c)+(b-d)i,
(a+bi)?(c+di)=(ac-bd)+(bc+ad)i 展开
(a+bi)+(c+di)=(a+c)+(b+d)i,
(a+bi)-(c+di)=(a-c)+(b-d)i,
(a+bi)?(c+di)=(ac-bd)+(bc+ad)i 展开
5个回答
展开全部
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) {
ComplexNumber cpx1, cpx2;
cpx1 = new ComplexNumber(0.0, 1.2);
cpx2 = new ComplexNumber();
cpx2.real = 8.5; cpx2.imaginary = 1.2;
System.out.println(cpx2.add(cpx1));
System.out.println(cpx2.sub(cpx1));
System.out.println(cpx2.multiply(cpx1));
}
}
class ComplexNumber {
public double real, imaginary;
public ComplexNumber(double _r, double _i) {
real = _r;
imaginary = _i;
}
public ComplexNumber() {}
public ComplexNumber add(ComplexNumber obj) {
return new ComplexNumber(real + obj.real, imaginary + obj.imaginary);
}
public ComplexNumber sub(ComplexNumber obj) {
return new ComplexNumber(real - obj.real, imaginary - obj.imaginary);
}
public ComplexNumber multiply(ComplexNumber obj) {
return new ComplexNumber(real * obj.real - imaginary * obj.imaginary,
imaginary * obj.real + real * obj.imaginary);
}
public String toString() {
return (real + " + " + imaginary + "i");
}
}
import java.util.*;
public class Main {
public static void main(String[] args) {
ComplexNumber cpx1, cpx2;
cpx1 = new ComplexNumber(0.0, 1.2);
cpx2 = new ComplexNumber();
cpx2.real = 8.5; cpx2.imaginary = 1.2;
System.out.println(cpx2.add(cpx1));
System.out.println(cpx2.sub(cpx1));
System.out.println(cpx2.multiply(cpx1));
}
}
class ComplexNumber {
public double real, imaginary;
public ComplexNumber(double _r, double _i) {
real = _r;
imaginary = _i;
}
public ComplexNumber() {}
public ComplexNumber add(ComplexNumber obj) {
return new ComplexNumber(real + obj.real, imaginary + obj.imaginary);
}
public ComplexNumber sub(ComplexNumber obj) {
return new ComplexNumber(real - obj.real, imaginary - obj.imaginary);
}
public ComplexNumber multiply(ComplexNumber obj) {
return new ComplexNumber(real * obj.real - imaginary * obj.imaginary,
imaginary * obj.real + real * obj.imaginary);
}
public String toString() {
return (real + " + " + imaginary + "i");
}
}
展开全部
这应该是作业题吧,想学好程序设计,要自己认真动手动脑。
下面是我个人的一点想法
public class ComplexNumber{
private double real;
private double imaginary;
public ComplexNumber(){}
public ComplexNumber(double real, double imaginary){
this.real = real;
this.imaginay = imaginary;
}
public ComplexNumber add(ComplexNumber obj){
return new ComplexNumber(this.real+this.imaginary,obj.real+obj.imaginary);
}
//其他的自己尝试去写
public String toString(){
return real+"+"imaginary+"i";
}
}
下面是我个人的一点想法
public class ComplexNumber{
private double real;
private double imaginary;
public ComplexNumber(){}
public ComplexNumber(double real, double imaginary){
this.real = real;
this.imaginay = imaginary;
}
public ComplexNumber add(ComplexNumber obj){
return new ComplexNumber(this.real+this.imaginary,obj.real+obj.imaginary);
}
//其他的自己尝试去写
public String toString(){
return real+"+"imaginary+"i";
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
这应该是作业题吧,想学好程序设计,要自己认真动手动脑。
下面是我个人的一点想法
public class ComplexNumber{
private double real;
private double imaginary;
public ComplexNumber(){}
public ComplexNumber(double real, double imaginary){
this.real = real;
this.imaginay = imaginary;
}
public ComplexNumber add(ComplexNumber obj){
return new ComplexNumber(this.real+this.imaginary,obj.real+obj.imaginary);
}
public String toString(){
return real+"+"imaginary+"i";
试一试
下面是我个人的一点想法
public class ComplexNumber{
private double real;
private double imaginary;
public ComplexNumber(){}
public ComplexNumber(double real, double imaginary){
this.real = real;
this.imaginay = imaginary;
}
public ComplexNumber add(ComplexNumber obj){
return new ComplexNumber(this.real+this.imaginary,obj.real+obj.imaginary);
}
public String toString(){
return real+"+"imaginary+"i";
试一试
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
唉 想当初刚学JAVA时,不管会不会的,我都是来这里回答问题以帮助自己进步。那时我也是一级。。。还是楼主自己好好学吧。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
12
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询