// A program that uses rational class import java.io.*; import rational; class use_rational { public static void main (String[] args) throws IOException { int a, b, c, d; BufferedReader stdin; stdin = new BufferedReader (new InputStreamReader (System.in)); System.out.println ("Enter four integers on separate lines: "); a = Integer.parseInt (stdin.readLine()); b = Integer.parseInt (stdin.readLine()); c = Integer.parseInt (stdin.readLine()); d = Integer.parseInt (stdin.readLine()); rational p = new rational(a,b); // p points to a new instance of rational rational q = new rational(c,d); // q points to a new instance of rational rational r = p.sum(q); // no need of new here, sum returns a new ratonal object System.out.println(p.str() + " + " + q.str() + " = " + r.str()); r.reduce(); System.out.println("Reduced sum is: " + r.str()); } }