public class Rat1 implements RatIF {

    public RatIF add(RatRepIF y) {
        try {
            return factory.make(numer() * y.denom()
                                 + y.numer() * denom(),
                                denom() * y.denom());
        } catch (ZeroDenominatorException zde) {
            System.err.println("Impossible exception " + zde);
        }
        System.exit(1);
        return null; // just to make the compiler happy :-(
    }

    public boolean equals(Object y) {
        return (y instanceof RatRepIF)
            && (numer() * ((RatRepIF)y).denom()
                == ((RatRepIF)y).numer() * denom());
    }

    public String toString() {
        return numer() + "/" + denom();
    }

    // ------ code above is client of that below --

    protected RatMetaIF factory;
    protected RatRepIF rep;

    public Rat1(RatMetaIF metaobj, RatRepIF r) {
        factory = metaobj;
        rep = r;
    } 

    // delegation of the following methods
    public int numer() { return rep.numer(); }
    public int denom() { return rep.denom(); }
}
