package cn.bunny.pattern9;

import lombok.Data;

import java.util.Random;

public class Adapter1 {
    public static void main(String[] args) {
        PowerAdapter powerAdapter = new PowerAdapter();
        Integer integer = powerAdapter.output220V();

        System.out.println("----------------");

        PowerAdapter powerAdapter1 = new PowerAdapter();
        powerAdapter1.output220V();
        Integer i = powerAdapter1.output380V();
    }

    // 电压输出
    interface PowerTarget {
        /**
         * 输出电压220V
         *
         * @return 输出电压
         */
        Integer output220V();
    }

    static class PowerAdapter extends Power implements PowerTarget {

        /**
         * 输出电压220V
         *
         * @return 输出电压
         */
        @Override
        public Integer output220V() {
            Integer output = super.getOutput();
            System.out.println("变压器交流" + output + "v转220v三相电变两项电。。。");

            double adapter = new Random().nextDouble(1.64, 1.72);
            Integer newOutput = (int) (output / adapter);
            System.out.println("变压器转换完成：电压输出为：" + newOutput);

            return newOutput;
        }
    }

    @Data
    static class Power {
        private Integer output = 380;

        public Integer output380V() {
            System.out.println("输出电压：" + output);
            return output;
        }
    }
}
