在不同的类上使用变量(枚举,其他包)

时间:2019-06-30 10:57:38

标签: java class variables enums package

这是我正在努力解决的问题。

1:我必须用不同的方法来枚举。 CENTIMETER,DECIMETER和METER。

2:我必须创建一个Volume类,该类使用以下变量来计算体积:int高度,宽度和深度,并且必须使用ENUM度量来计算正确的体积。

3:我必须创建一个具有可变Volume loadingvolume的Truck类。

现在我的问题是:如何使用必须在Truck上使用的构造函数来计算体积。

编辑:我想我已经用代码管理了一些改进,但还没有完成。我从拾音器中更改了构造函数。但是现在我将其作为Volume的输出:Volume @ 7ea987ac


        public enum Measure {
        CENTIMETER(1), DECIMETER(1000), METER(1000000);
        private final int factor;

        Maat(int factor) {
            this.factor = factor;
        }

        public int getFactor() {
            return factor;
        }
    }


    import be.vdab.voertuigen.Maat;

    public final class Volume {

        private final int width;
        private final int height;
        private final int depth;
        private final Measure measure;

        public Volume(int width, int heigth, int depth, Measure measure) {

            this.width = getWidth();
            this.heigth = getHeigth();
            this.depth = getDepth();
            this.measure = measure;
        }

        public int getWuidth() {
            return breedte;
        }

        public int getHeigth() {
            return hoogte;
        }

        public int getDepth() {
            return diepte;
        }

        public Measure getMeasure() {
            return maat;
        }

        public long getVolume() {
            long volumeInMeasure = getWidth() * getHeigth() * getDepth();
            Maat measureForCalc = getMaat();
            return volumeInMeasure * measureForCalc.getFactor();
        }
    }

    import be.vdab.util.Volume;

    public class Pickup{

        private Volume loadingVolume;

        public Vrachtwagen(int heigth, int width, int depth, Measure measure) {
            ***this.loadingVolume = new Volume(heigth,width,depth,measure)***



        public Volume getLoadingVolume() {
            return loadingVolume;
        }

        public void setLoadingVolume(Volume loadingVolume) {
            loadingVolume.getVolume();
        }
    ~~~~

0 个答案:

没有答案