/** * This class implements a rational number object, * and provides methods for performing arithmetic * on rational numbers. * @see java.lang.Math * @author Schultzie von Wienerschnitzel III * @version 3.14159 */ public class Rational { /* instance variables */ private int numer; // numerator private int denom; // denominator /* private utility method for setting data */ private void set( int n, int d ) { numer = n; denom = d; } /** * Default constructor creates the rational 0/1. */ public Rational( ) { set( 0, 1 ); } /** * Standard constructor given numerator and denominator. * @param n The numerator * @param d The denominator */ public Rational( int n, int d ) { set( n, d ); } /** * Multiplies two rational numbers and returns their the product. * @param q The first operand. * @param r The second operand. * @return A reference to a newly created Rational with the sum. */ public static Rational multiply( Rational q, Rational r) { return new Rational( q.numer * r.numer, q.denom *r.denom ); } }