Topic: 关于继承

  Print this page

1.关于继承 Copy to clipboard
Posted by: 紫蝴蝶
Posted on: 2005-05-05 19:52

谁能帮我看看这段程序这么写为什么不行,谢谢啦
import java.io.*;
public class TestComplexNumber
{ public static void main(String args[])
{
double x=0,y=0;
String m,n;
ComplexNumber MyComplexNumber=new ComplexNumber();
System.out.println("input the real part");
try{
BufferedReader in=
new BufferedReader(new InputStreamReader(System.in));
m=in.readLine();
x=Double.parseDoubleMusic;
}catch(IOException e){}
System.out.println("input the imaginary part");
try{
BufferedReader in=
new BufferedReader(new InputStreamReader(System.in));
n=in.readLine();
y=Double.parseDoubleThumbs down;
}catch(IOException e){}
ComplexNumber a=new ComplexNumber(x,y);
System.out.println(MyComplexNumber);
}
}
class ComplexNumber
{
double x,y;
public ComplexNumber(double real, double imaginary)
{
this.x = real;
this.y = imaginary;
}
public double real()
{
return x;
}
public double imaginary()
{
return y;
}
public String toString()
{
return "{" + x + "," + y + "}";
}
public ComplexNumber add(ComplexNumber a)
{
return new ComplexNumber(this.x + a.x, this.y+a.y);
}

public ComplexNumber multiply(ComplexNumber a)
{
return new ComplexNumber(this.x*a.x - this.y*a.y, this.x*a.y + this.y*a.x);
}
}
class MyComplexNumber extends ComplexNumber
{
public String toString()
{
return x+" +"+" "+y+"i";
}
}
TestComplexNumber.java:7: ComplexNumber(double,double) in ComplexNumber cannot b
e applied to ()
ComplexNumber MyComplexNumber=new ComplexNumber();
^
TestComplexNumber.java:56: ComplexNumber(double,double) in ComplexNumber cannot
be applied to ()
class MyComplexNumber extends ComplexNumber
^
2 errors

2.Re:关于继承 [Re: 紫蝴蝶] Copy to clipboard
Posted by: jinguizi
Posted on: 2005-05-05 20:04

不把想法写出来,就让别人读你的代码,太累

3.Re:关于继承 [Re: 紫蝴蝶] Copy to clipboard
Posted by: 紫蝴蝶
Posted on: 2005-05-06 21:18

ComplexNumber是一个已有的复数类,x,y分别代表实部和虚部,该类只支持加法(add)和乘法(multiply)计算,欲创建一个MyComplexNumber类,扩充ComplexNumber类的功能:
原来的toString方法得到的复数表示是{3.5,12.81}的形式,现想在新的类里面修改为3.5+12.81i的形式

4.Re:关于继承 [Re: 紫蝴蝶] Copy to clipboard
Posted by: baixiaotian
Posted on: 2005-05-10 23:06

String m,n;//变量没有初始化


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923