Java 程序设计题 急急急
定义一个盒子类Box,包括三个私有成员变量(width、length、height)、一个构造方法和showBox()方法。构造方法用来初始化变量showBox()方法无...
定义一个盒子类 Box ,包括三个私有成员变量( width 、 length 、 height)、一个构造方法和 showBox ( )方法。构造方法用来初始化变量 showBox ()方法无参数,用于输出变量( width 、legth和height)的值
展开
展开全部
代码如下
class Box{
private int width;
private int length;
private int height;
public Box(int width,int length,int height){
this.width = width;
this.length = length;
this.height = height;
}
public void showBox(){
System.out.println("盒子的width、length、height分别为"+width+","+length+","+height);
}
}
如果有帮助到你,请点击采纳
追问
public class Box{
private double width;
private double length;
private double height;
public Box(double width, double length, double height){
this.width = width;
this.length = length;
this.height = height;
}
public void showBox(){
System.out.printf("width=%f; length=%f; height=%f", width, length, height);
}
}
这个是对的吗
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
class box
{
double length,width,height;
public box(double length,double width,double height){
this.length = length;
this.width = width;
this.height = height;
}
public void setlength(double x){
length = x;
}
public void setwidth(double x){
width = x;
}
public void setheight(double x){
height = x;
}
public double getlength(){
return length;
}
public double getwidth(){
return width;
}
public double getheight(){
return height;
}
public double getarea(){
return (lenght*width+length*height+width*length)*2;
}
public double getvolumn(){
return length*height*width;
}
}
public class testbox
{
public static void main(string [] args){
box b = new box(2,4,5);
}
}
{
double length,width,height;
public box(double length,double width,double height){
this.length = length;
this.width = width;
this.height = height;
}
public void setlength(double x){
length = x;
}
public void setwidth(double x){
width = x;
}
public void setheight(double x){
height = x;
}
public double getlength(){
return length;
}
public double getwidth(){
return width;
}
public double getheight(){
return height;
}
public double getarea(){
return (lenght*width+length*height+width*length)*2;
}
public double getvolumn(){
return length*height*width;
}
}
public class testbox
{
public static void main(string [] args){
box b = new box(2,4,5);
}
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
给点悬赏呗,我可以写
更多追问追答
追问
悬赏给了,麻烦写一下
追答
放假了都不休息啊。等等
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询