David I. Smith
2005-01-15 23:58:50 UTC
I ran the code that was added to the Project 1 page, there were some
errors with it. I've included a fixed version below
public static void main( String [] args ) {
Rational r = new Rational( 1, 2 );
Rational s = new Rational( 2, 3 );
Rational q = s.minus( r );
if ( q.getNumerator() != 1 )
throw new RuntimeException( "Wrong numerator: expecting 1" );
if ( q.getDenominator() != 6 )
throw new RuntimeException( "Wrong denominator: expecting
6" );
q = s.divide( r );
if ( q.getNumerator() != 4 )
throw new RuntimeException( "Wrong numerator: expecting 4" );
if ( q.getDenominator() != 3 )
throw new RuntimeException( "Wrong denominator: expecting
3" );
}
errors with it. I've included a fixed version below
public static void main( String [] args ) {
Rational r = new Rational( 1, 2 );
Rational s = new Rational( 2, 3 );
Rational q = s.minus( r );
if ( q.getNumerator() != 1 )
throw new RuntimeException( "Wrong numerator: expecting 1" );
if ( q.getDenominator() != 6 )
throw new RuntimeException( "Wrong denominator: expecting
6" );
q = s.divide( r );
if ( q.getNumerator() != 4 )
throw new RuntimeException( "Wrong numerator: expecting 4" );
if ( q.getDenominator() != 3 )
throw new RuntimeException( "Wrong denominator: expecting
3" );
}