设计一个box类 并计算容积

img

如有帮助,望点击我回答右上角【采纳】按钮支持一下。

public class Box {
    //长、宽、高、容积、使用容积
    private double length;
    private double wide;
    private double height;
    private double volume;
    private double useVolume;
    public Box(double length, double wide, double height) {
        this.length = length;
        this.wide = wide;
        this.height = height;
    }
   public void getVolume(){
        volume=length*wide*height;
    }
    public void changeVo(double volume){
        useVolume=useVolume+volume;
    }
    public void emptyVo(){
        useVolume=0;
    }
    public boolean isFullVo(){
        if (useVolume==volume){
            return true;
        }
        return false;
    }
}
public class Main {

}

class box {
    private int x, y, z, v, used_v;

    public box(int x, int y, int z) {
        this.x = x;
        this.y = y;
        this.z = z;
    }

    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }

    public int getZ() {
        return z;
    }

    public void setZ(int z) {
        this.z = z;
    }

    public int getV() {
        return v;
    }

    public void calcV(int v) {
        this.v = x * y * z;
    }

    public int getUsed_v() {
        return used_v;
    }

    public void setUsed_v(int used_v) {
        this.used_v = used_v;
    }

    public void resetUsed_v() {
        this.used_v = 0;
    }

    public boolean isFull() {
        if (v <= used_v)
            return true;
        return false;
    }

}