import java.rmi.*; import java.rmi.server.*; public class rational extends UnicastRemoteObject implements rrat { public int n; public int d = 1; public rational(int a, int b) throws RemoteException { super(); int g = gcd(a,b); n = a/g; if (n!=0) d=b/g; } public int getn() { return n; } public int getd() { return d; } public void setn(int x) { n=x; } public void setd(int x) { if (x!=0) d=x; } private static int gcd(int a, int b) { if (a==0) return b; else return gcd(b%a,a); } public boolean eqr(rrat r) { boolean answer = false; try { answer = n*r.getd() == d*r.getn(); } catch (java.rmi.RemoteException rre) {rre.printStackTrace();} return answer; } public void invert() { int t = n; n = d; d = t; } public String toStr() { return n+"/"+d; } public void change(bigobject b) { // n += b.x; // works! b.x += 1; // doesn't change anything! } public rrat make(String newrat, int n, int d) { rational nr = null; try { nr = new rational(n,d); Naming.rebind(newrat,nr); } catch (Exception ee1) {ee1.printStackTrace();} return nr; } // make public static void main(String[] args) { rational r1, r2; try { r1 = new rational(1,2); r2 = new rational(3,6); Naming.rebind("rat1",r1); Naming.rebind("rat2",r2); } catch (Exception ee) {ee.printStackTrace();} } // main } // rational