![]() |
#2
红柚2018-10-20 12:57
|



这是程序代码

class Box{
double width;
double height;
double depth;
double volume(){
return width*height*depth;
}
void setDim(double w, double h, double d){
width=w;
height=h;
depht=d;
}
}
class BoxTest{
public static void main(String[] s)
Box myBox=new Box();
Box hisBox=new Box();
double myVol,hisVol;
myBox.setDim(10, 20, 15);
hisBox.setDim(3, 6, 9);
myVol=myBox.volume();
hisVol=hisBox.volume();
System.out.println("myBox is"+myBox);
System.out.println("hisBox is"+hisBox);
}
double width;
double height;
double depth;
double volume(){
return width*height*depth;
}
void setDim(double w, double h, double d){
width=w;
height=h;
depht=d;
}
}
class BoxTest{
public static void main(String[] s)
Box myBox=new Box();
Box hisBox=new Box();
double myVol,hisVol;
myBox.setDim(10, 20, 15);
hisBox.setDim(3, 6, 9);
myVol=myBox.volume();
hisVol=hisBox.volume();
System.out.println("myBox is"+myBox);
System.out.println("hisBox is"+hisBox);
}
只有本站会员才能查看附件,请 登录