Java问题,求教大神,在线等,定义类Box 定义double型的三个变量:length,width,height具体如下

定义类Box
定义double型的三个变量:length,width,height

定义构造方法Box(double length,double width,double height)
初始化length,width,height三个变量

定义三个普通方法set...(double x):用变量值x修改长、宽、高的值。
定义三个普通方法get...():返回长、宽、高的值。
定义普通方法getArea():计算其表面积;
定义普通方法getVolumn():计算其体积。

编写主类TestBox,调用Box中定义的变量和方法,并将结果输出。

2.定义类LeapYear
定义普通方法getLeapYear(int year):
实现判断year是否是闰年的功能。

编写主类TestLeapYear:从键盘上任意输入年份数,调用LeapYear的方法
getLeapYear(int year),判断是否是闰年,并输出结果。
3.定义类Function
定义六个double型变量:a,b,c,d,m,n
定义三个构造方法:
Function(double a,double b)// 一元一次方程
Function(double a,double b,double c)//一元二次方程
Function(double a,b,c,d,m,n)//二元一次方程
定义三个同名普通方法求解方程:
doFunction(double a,b)
doFunction(double a,b,c)
doFunction(double a,b,c,d,m,n)
编写主类TestFunction,对Function类的方法进行调用,求解相应的方程。
并输出求解的结果。

第1个回答  推荐于2016-02-10
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);

}
}本回答被提问者采纳
相似回答