FileDocCategorySizeDatePackage
MyRationalC.javaAPI DocExample2569Fri Oct 01 15:10:22 BST 1999None

MyRationalC

public class MyRationalC extends JPubRationalC implements oracle.sql.CustomDatumFactory, oracle.sql.CustomDatum

Fields Summary
static final MyRationalC
_MyRationalCFactory
Constructors Summary
public MyRationalC()

 
    super();
  
public MyRationalC(int numerator, int denominator)

    super();
    setNumerator(numerator);
    setDenominator(denominator);
  
Methods Summary
public oracle.sql.CustomDatumcreate(oracle.sql.Datum d, int sqlType)

    if (d == null) return null;
    MyRationalC o = new MyRationalC();
    o._struct = new MutableStruct((STRUCT) d, _sqlType, _factory);
    return o;
  
public static intgcd(int x, int y)

    if (x < y)
      return gcd(y, x);

    if (x % y == 0)
      return y;

    return gcd (y, x / y);
  
public static oracle.sql.CustomDatumFactorygetFactory()

     
  
    return _MyRationalCFactory;
  
public voidnormalize()

    int n = getNumerator();
    int d = getDenominator();

    int g = gcd(n, d);
    setNumerator(n/g);
    setDenominator(d/g); 
  
public MyRationalCplus(MyRationalC x)

    return new MyRationalC(
      getNumerator() * x.getDenominator() +
      x.getNumerator() * getDenominator(), 
      getDenominator() * x.getDenominator());
  
public floattoReal()

    return ((float) getNumerator())/getDenominator();
  
public java.lang.StringtoString()

    try
    {
       return getNumerator() + "/" + getDenominator();
    }
    catch (SQLException e)
    {
       return null;
    }