用JAVA编程,要求如下:
定义长方体类Box,有成员变量长length,宽width,高height,有成员方法:显示输出长、宽、高信息的方法print(),计算体积的方法volume(),计算表...
定义长方体类Box,有成员变量长length,宽width,高height,有成员方法:显示输出长、宽、高信息的方法print(),计算体积的方法volume(),计算表面积的方法area()。并定义重载的带参、无参构造方法。
展开
展开全部
/*
* 定义长方体类Box,有成员变量长length,宽width,高height,有成员方法:显示输出长、宽、高信息的方法print(),
* 计算体积的方法volume(),计算表面积的方法area()。并定义重载的带参、无参构造方法。
*/
class Box{
private double length;
private double width;
private double height;
Box(){
}
Box(double length,double width,double height){
this.length = length;
this.width = width;
this.height = height;
}
public double volume(){
return length*width*height;
}
public double area(){
return length*width+length*height+width*height;
}
public void print(){
System.out.println("length:"+length+"\t"+"width:"+width+"\t"+"height:"+height+
"\n"+"volume:"+volume()+"\t"+"area:"+area());
}
}
public class A {
public static void main(String[] args){
Box b = new Box(10,20,10);
b.print();
}
}
* 定义长方体类Box,有成员变量长length,宽width,高height,有成员方法:显示输出长、宽、高信息的方法print(),
* 计算体积的方法volume(),计算表面积的方法area()。并定义重载的带参、无参构造方法。
*/
class Box{
private double length;
private double width;
private double height;
Box(){
}
Box(double length,double width,double height){
this.length = length;
this.width = width;
this.height = height;
}
public double volume(){
return length*width*height;
}
public double area(){
return length*width+length*height+width*height;
}
public void print(){
System.out.println("length:"+length+"\t"+"width:"+width+"\t"+"height:"+height+
"\n"+"volume:"+volume()+"\t"+"area:"+area());
}
}
public class A {
public static void main(String[] args){
Box b = new Box(10,20,10);
b.print();
}
}
展开全部
public class Box{
private double length;
private double width;
private double height;
private void print(){
System.out.println(this.length+" "+this.width+" "+this.height);
}
private double volume(){
return this.length*this.width*this.height;
}
private double area(){
return (this.length*this.width+this.length*this.height+this.width*this.height)*2
}
private Box(){}
private Box(double length,double width,double height){
this.length=length;
this.width=width;
this.height=height;
}
}
private double length;
private double width;
private double height;
private void print(){
System.out.println(this.length+" "+this.width+" "+this.height);
}
private double volume(){
return this.length*this.width*this.height;
}
private double area(){
return (this.length*this.width+this.length*this.height+this.width*this.height)*2
}
private Box(){}
private Box(double length,double width,double height){
this.length=length;
this.width=width;
this.height=height;
}
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
public static void main (String [] arge){
//调用定义的方法
volume(10,20,30);
area(10,20);
}
/*
定义求面积的方法
*/
publice statice void area(double length,width){
System.out.print(length*width);
}
publice statice void volume(double length,width,heigth){
System.out.print(length*width*higth);
}
好像是这样的因为在手机上给你打得估计有些要改…思路反正是这样的!
//调用定义的方法
volume(10,20,30);
area(10,20);
}
/*
定义求面积的方法
*/
publice statice void area(double length,width){
System.out.print(length*width);
}
publice statice void volume(double length,width,heigth){
System.out.print(length*width*higth);
}
好像是这样的因为在手机上给你打得估计有些要改…思路反正是这样的!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |