用java编写一个程序

来源:百度知道 编辑:UC知道 时间:2024/05/12 15:27:59
用java编写一个程序,得出3个不同盒子的体积。将每个盒子的高度、宽度和长度参数的值传递给构造方法,计算并显示体积。(其中计算和显示用两个方法实现)

最好简单一点的哦~~呵呵谢谢大家啦!

方法比较简单:
Test.java

public class Test{
int length;
int wide;
int height;
public Test()
{
}
int cout(int a,int b,int c) {
int count = 0;
length = a;
wide = b;
height = c;
count = length*wide*height;
return count;
}
void output(int count) {
System.out.println("体积:"+count);
}
public static void main(String [] args) {
int answer;
Test test = new Test();
answer = test.cout(1,2,3);
System.out.println("第一个的体积:");
test.output(answer);
answer = test.cout(2,3,4);
System.out.println("第二个的体积:");
test.output(answer);
}
}

public class Rectangle {

private float width;
private float height;
private float area;
public Rectangle(float width,float height)
{
this.width=width;
this.height=height;
}
public void jisuan()
{