一道Java 编程题 帮忙做一下
定义长方体类Box,定义成员变量length,width,height分别表示长方体的长,宽,高。定义构造函数初始化三个成员变量;定义求长方体的表面积的方法并返回结果;定...
定义长方体类Box,定义成员变量length,width,height分别表示长方体的长,宽,高。定义构造函数初始化三个成员变量;定义求长方体的表面积的方法并返回结果;定义求体积的方法并返回结果;定义方法toString()用来将长方体的长,宽,高以及面积,体积信息连接成字符串返回。
编写应用程序,测试Box类,使用该类中的各个方法。
这是 题目 展开
编写应用程序,测试Box类,使用该类中的各个方法。
这是 题目 展开
2个回答
展开全部
public class Box{
double length;
double width;
double height;
public Box(double length, double width, double height) {
this.length = length;
this.width= width;
this.height= height;
this.sex = sex;
}
public Box() {
}
public double getHeight() {
return height;
}
public void setHeight(double height) {
this.height = height;
}
public double getLength() {
return length;
}
public void setLength(double length) {
this.length = length;
}
public double getWidth() {
return width;
}
public void setWidth(double width) {
this.width = width;
}
public double getMj() {
return this.getLength()*this.getWidth();
}
public double getTj() {
return this.getLength()*this.getWidth()*this.getHeight();
}
public String toString() {
return "长:"+this.getLength()+"宽:"+this.getWidth()+"高:"+this.getHeight()+"面积:"+this.getMj()+"体积:"+this.getTj();
}
public static void main(String[] args) {
Box box=new Box(12,23,4);
System.out.println(box.toString())
}
}
double length;
double width;
double height;
public Box(double length, double width, double height) {
this.length = length;
this.width= width;
this.height= height;
this.sex = sex;
}
public Box() {
}
public double getHeight() {
return height;
}
public void setHeight(double height) {
this.height = height;
}
public double getLength() {
return length;
}
public void setLength(double length) {
this.length = length;
}
public double getWidth() {
return width;
}
public void setWidth(double width) {
this.width = width;
}
public double getMj() {
return this.getLength()*this.getWidth();
}
public double getTj() {
return this.getLength()*this.getWidth()*this.getHeight();
}
public String toString() {
return "长:"+this.getLength()+"宽:"+this.getWidth()+"高:"+this.getHeight()+"面积:"+this.getMj()+"体积:"+this.getTj();
}
public static void main(String[] args) {
Box box=new Box(12,23,4);
System.out.println(box.toString())
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询