import java.util.*;

public class Main {

    enum Type {
        Normal(10), Rare(2), Yoba(1);

        int coefficient;
        Type(int coefficient) { this.coefficient = coefficient; }
    }

    static class Item {
        String name;
        int weight;
        Type type;
        double expectedProbability;

        public Item(String name, int weight, Type type, double expectedProbability) {
            this.name = name;
            this.weight = weight;
            this.type = type;
            this.expectedProbability = expectedProbability;
        }

        @Override
        public String toString() { return name; }
    }

    static class WeightedItemSelector {
        private final NavigableMap<Integer, Item> map = new TreeMap<>();
        private final Random random = new Random();
        private final int maxRange;

        public WeightedItemSelector(Item... items) {
            int currentWeight = 0;
            for (Item item : items) {
                currentWeight += item.weight * item.type.coefficient;
                map.put(currentWeight, item);
            }
            maxRange = currentWeight;
        }

        public Item getNext() {
            return map.higherEntry(random.nextInt(maxRange)).getValue();
        }
    }



    private static int iterCount = 1000000;

    public static void main(String[] args) {
        WeightedItemSelector selector = new WeightedItemSelector(
                new Item("Шапка пиздоглазия", 5, Type.Normal, 50 / 207d),
                new Item("Зелье упоротости", 7, Type.Normal, 70 / 207d),
                new Item("Картонный щит", 6, Type.Normal, 60 / 207d),
                new Item("Меч-опиздюливатель", 5, Type.Rare, 10 / 207d),
                new Item("Шлем из мамкиной кастрюли", 8, Type.Rare, 16 / 207d),
                new Item("Хуй дракона", 1, Type.Yoba, 1 / 207d)
        );

        Map<Item, Integer> counters = new HashMap<>();
        for (int i = 0; i < iterCount; i++) {
            counters.compute(selector.getNext(), (k, v) -> v == null ? 1 : v + 1);
        }

        counters.entrySet().forEach(e -> System.out.println(String.format("%s: expected %f, actual %f", e.getKey().name, e.getKey().expectedProbability, e.getValue().doubleValue() / iterCount)));

    }

}
