class RatioNumber extends Number implements Comparable<RatioNumber> {

    public RatioNumber add(RatioNumber other) {
        if (other == null) {
            return new RatioNumber(this.value, this.ratio);
        } else {
            if (this.equals(RatioNumber.ZERO)) {
                return new RatioNumber(other.value, other.ratio);
            } else if (other.equals(RatioNumber.ZERO)) {
                return new RatioNumber(this.value, this.ratio);
            } else {
                double value = this.value + other.value;
                double ratio = (this.ratio * this.value + other.ratio * other.value) / value;
                return new RatioNumber(value, ratio);
            }
        }
    }

    public  RatioNumber(double value, double ratio);

}