请在 下方输入 要搜索的题目:

设计并实现Box类,它包含盒子的高度、宽带和深度的实例数据:还包含布尔变量full这个实例数据,变量full表示盒子是否满了。所有数据都定义为私有。定义Box构造函数接收并初始化盒子的高度、宽带和深度。每次新创建的Box都为空,构造函数将full初始化为假。该类所有实例都有getter和setter方法;该类还包含了一个计算盒子体积的方法。
该类包含一个toString方法,用来返回一行关于盒子的描述。
例如,输入的长、宽、高分别为4,如果盒子为空,则输出:
Box is empty, The Volumn is 64
若将盒子的宽度修改为5,盒子设置为满,则输出:
Box is full, The Volumn is 80
创建一个测试类BoxTest,其main方法输入盒子的长、宽、高,实例化一个Box对象,并输出盒子的描述。
 根据以下的测试类,在空格出填入Box类的设计程序。

(1分)

 

class (1分) {

    private boolean (1分);

    private int width;

    private int height;

    private int lenght;

 

    public Box((1分)) {

        full = false;

        this.width = width;

        this.height = height;

        this.lenght = lenght;

    }

 

    public (1分) isFull() {

        return full;

    }

 

    public void setFull(boolean full) {

        this.full = full;

    }

 

    public int getWidth() {

        return width;

    }

 

    public void setWidth(int width) {

        this.width = width;

    }

 

    public int getHeight() {

        return height;

    }

 

    public void setHeight(int h) {

        this.height = height;

    }

 

    public int getLenght() {

        return lenght;

    }

 

    public void setLenght(int lenght) {

            this.lenght = lenght;

    }

 

    public int getVolumn() {

       (1分)

    }

 

    @Override

    public String (1分) {

        return "Box is " + (full ? "full" : "empty") + ", The Volumn is " + getVolumn();

    }

}

public class Main {

    public (1分) main(String] args) {

        Scanner input = new Scanner(System.in);

        int w = input.nextInt();

        int h = input.nextInt();

        int l = input.nextInt();

        Box box1 = (1分)

        System.out.println(box1.toString());

        box1.setWidth(5);

        box1.setFull((1分));

        System.out.println(box1.toString());

 

    }

}

 

发布时间:2024-04-17 09:52:00
推荐参考答案 ( 由 搜题小帮手 官方老师解答 )
联系客服
答案:

以下文字与答案无关

提示:有些试题内容 显示不完整,文字错误 或者 答案显示错误等问题,这是由于我们在扫描录入过程中 机器识别错误导致,人工逐条矫正总有遗漏,所以恳请 广大网友理解。

相关试题
登录 - 搜题小帮手
点我刷新
立即注册
注册 - 搜题小帮手
点我刷新
立即登录