注册 登录
编程论坛 新人交流区

[求助]我的这个程序不出结果

北恩 发布于 2007-10-30 11:28, 311 次点击
大家帮帮我啊
这个程序不出 结果
有异常
可是我不知道怎么改
一个就是求长方形的面积什么的
的二个是继承
然后重写父类的某些方法
9 回复
#2
bluelxxm2007-10-30 11:30

代码呢

#3
北恩2007-10-30 12:22

public class MyRectangle {
private int rxUp,ryUp,lxUp,lyUp;
int width;
int height;
int area1;

public MyRectangle(int rxUp,int ryUp,int lxUp,int lyUp){
this.lxUp=lxUp;
this.lyUp=lyUp;
this.rxUp=rxUp;
this.ryUp=ryUp;
}//构造方法

public int getW(){
width=lyUp-ryUp;
return width;
}

public int getH(){
height=rxUp-lxUp;
return height;
}

public int area(int width,int height){
this.getH();
this.getW();
area1=height*width;
return area1;
}

public String toString(){
return "宽:"+width+" 长:"+height+" 面积:"+area1;
}

/*public int getrxUp(){
return rxUp;
}
public int getlxUp(){
return lxUp;
}
public int getryUp(){
return ryUp;
}
public int getlyUp(){
return lyUp;
}*/

public static void main(String args[]){
MyRectangle a= new MyRectangle(20,5,10,20);
a.area(a.getH(),a.getW());
System.out.println(a.toString());
}
}

public class MyCube extends MyRectangle{
MyRectangle mian;
int d;
long areac;
long vol;

public MyCube(int rxUp,int ryUp,int lxUp,int lyUp,int f){
super(rxUp,ryUp,lxUp,lyUp);
this.d=f;
}

public long volume(){
vol=mian.width*mian.height*d;
return vol;
}

public long cubearea(){
areac=2*(super.area(mian.width,mian.height)+super.area(mian.width,d)+super.area(d,mian.height));
return areac;
}

public static void main(String args[]){
try{
MyCube mc=new MyCube(20,5,10,20,6);
//mc.getH();
//mc.getW();
System.out.println("立方体的表面积:"+mc.cubearea());
System.out.println("立方体的体积:"+mc.volume());
}catch(NullPointerException ex){
//System.out.println("the error is"+ex);
//ex.printStackTrace();
System.out.println("the error is:"+ex.getMessage());
}
}
}


#4
wangmingqun2007-10-30 13:06
    把代码贴出来,大家好看看,然后才能给你改啊.等你的代码啊.
#5
北恩2007-11-02 20:51

我帖了代码了啊
怎么还是没动静呢???
帮帮我啊
很向知道为什么啊

#6
酷儿2007-11-02 21:46

一个JAVA里不能有2个PUBLIC类

#7
Donet2007-11-02 22:21
你有两个程序入口这是不行的
#8
酷儿2007-11-02 22:37

class MyRectangle {
private int rxUp,ryUp,lxUp,lyUp;
int width;
int height;
int area1;

public MyRectangle(int rxUp,int ryUp,int lxUp,int lyUp){
this.lxUp=lxUp;
this.lyUp=lyUp;
this.rxUp=rxUp;
this.ryUp=ryUp;
}//构造方法

public int getW(){
width=lyUp-ryUp;
return width;
}

public int getH(){
height=rxUp-lxUp;
return height;
}

public int area(int width,int height){
this.getH();
this.getW();
area1=height*width;
return area1;
}

public String toString(){
return "宽:"+width+" 长:"+height+" 面积:"+area(width,height);
}

/*public int getrxUp(){
return rxUp;
}
public int getlxUp(){
return lxUp;
}
public int getryUp(){
return ryUp;
}
public int getlyUp(){
return lyUp;
}*/
}

class MyCube extends MyRectangle{

int d;
long areac;
long vol;

public MyCube(int rxUp,int ryUp,int lxUp,int lyUp,int f){
super(rxUp,ryUp,lxUp,lyUp);
this.d=f;
}

public long volume(){
vol=super.width*super.height*d;
return vol;
}

public long cubearea(){
areac=2*(super.area(super.width,super.height)+super.area(super.width,d)+super.area(d,super.height));
return areac;
}
}
public class bc_china{
public static void main(String args[]){
try{
MyCube mc=new MyCube(20,5,10,20,6);
//mc.getH();
//mc.getW();
System.out.println("立方体的表面积:"+mc.cubearea());
System.out.println("立方体的体积:"+mc.volume());
}catch(NullPointerException ex){
//System.out.println("the error is"+ex);
//ex.printStackTrace();
System.out.println("the error is:"+ex.getMessage());
}
}
}

--------------------Configuration: <Default>--------------------
立方体的表面积:300
立方体的体积:900

Process completed.

[此贴子已经被作者于2007-11-2 22:40:40编辑过]

#9
北恩2007-11-08 13:56
回复:(酷儿)一个JAVA里不能有2个PUBLIC类

这个我知道
只是在这里我把他们放在一起
在我的电脑上运行的时候
是存在了两个文件
不过
还是谢谢啦

#10
北恩2007-11-08 13:57
回复:(Donet)你有两个程序入口这是不行的
什么叫做两个程序入口啊
能不能详细点说呢
谢谢
1