Discussion:
Changes to Project 1
(too old to reply)
David I. Smith
2005-01-15 23:58:50 UTC
Permalink
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" );
}
Calvin Cheung
2005-01-16 20:21:07 UTC
Permalink
Slightly modified version to print out a message if actually the test ran.

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" );
else if ( q.getDenominator() != 6 )
throw new RuntimeException( "Wrong denominator: expecting
6" );
else System.out.println("Subtraction test successful.");

q = s.divide( r );

if ( q.getNumerator() != 4 )
throw new RuntimeException( "Wrong numerator: expecting 4" );
else if ( q.getDenominator() != 3 )
throw new RuntimeException( "Wrong denominator: expecting
3" );
else System.out.println("Division test successful.");
}

Calvin
Post by David I. Smith
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" );
}
Douglas Harder
2005-01-17 19:33:37 UTC
Permalink
I like the modification. Added to the specification.

Douglas
Post by Calvin Cheung
Slightly modified version to print out a message if actually the test ran.
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" );
else if ( q.getDenominator() != 6 )
throw new RuntimeException( "Wrong denominator: expecting
6" );
else System.out.println("Subtraction test successful.");
q = s.divide( r );
if ( q.getNumerator() != 4 )
throw new RuntimeException( "Wrong numerator: expecting 4" );
else if ( q.getDenominator() != 3 )
throw new RuntimeException( "Wrong denominator: expecting
3" );
else System.out.println("Division test successful.");
}
Calvin
Post by David I. Smith
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" );
}
Nahid
2005-01-18 20:13:34 UTC
Permalink
Is it just me or the expected answers for the subtractiona and division is
wrong in the sample main program?

As Prof Harder said: "The requirements for minus and divide suggest that
s.minus(r) and s.divide(r) should calculate r - s and r / s."

s.minus (r) = r - s = 1/2 - 2/3 = -1/6
s.divide (r) = r/s = 1/2 / 2/3 = 4/6
Post by Douglas Harder
I like the modification. Added to the specification.
Douglas
Post by Calvin Cheung
Slightly modified version to print out a message if actually the test ran.
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" );
Post by Calvin Cheung
else if ( q.getDenominator() != 6 )
throw new RuntimeException( "Wrong denominator: expecting
6" );
else System.out.println("Subtraction test successful.");
q = s.divide( r );
if ( q.getNumerator() != 4 )
throw new RuntimeException( "Wrong numerator: expecting
4" );
Post by Calvin Cheung
else if ( q.getDenominator() != 3 )
throw new RuntimeException( "Wrong denominator: expecting
3" );
else System.out.println("Division test successful.");
}
Calvin
Post by David I. Smith
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" );
Post by Calvin Cheung
Post by David I. Smith
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" );
Post by Calvin Cheung
Post by David I. Smith
if ( q.getDenominator() != 3 )
throw new RuntimeException( "Wrong denominator: expecting
3" );
}
Adam Bertrand
2005-01-18 22:57:51 UTC
Permalink
s.minus(r) should output s-r... which makes sense considering how you
read it...

same with divide.

-Adam
Post by Nahid
Is it just me or the expected answers for the subtractiona and division is
wrong in the sample main program?
As Prof Harder said: "The requirements for minus and divide suggest that
s.minus(r) and s.divide(r) should calculate r - s and r / s."
s.minus (r) = r - s = 1/2 - 2/3 = -1/6
s.divide (r) = r/s = 1/2 / 2/3 = 4/6
Post by Douglas Harder
I like the modification. Added to the specification.
Douglas
Post by Calvin Cheung
Slightly modified version to print out a message if actually the test ran.
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" );
Post by Calvin Cheung
else if ( q.getDenominator() != 6 )
throw new RuntimeException( "Wrong denominator: expecting
6" );
else System.out.println("Subtraction test successful.");
q = s.divide( r );
if ( q.getNumerator() != 4 )
throw new RuntimeException( "Wrong numerator: expecting
4" );
Post by Calvin Cheung
else if ( q.getDenominator() != 3 )
throw new RuntimeException( "Wrong denominator: expecting
3" );
else System.out.println("Division test successful.");
}
Calvin
Post by David I. Smith
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" );
Post by Calvin Cheung
Post by David I. Smith
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" );
Post by Calvin Cheung
Post by David I. Smith
if ( q.getDenominator() != 3 )
throw new RuntimeException( "Wrong denominator: expecting
3" );
}
David I. Smith
2005-01-19 13:05:09 UTC
Permalink
If you take a look at the uw.ece.ec250announce board, you'll notive that
the original specification indicated this, but because it was rather
confusing, and didn't read well the prof changed the spec.
Post by Nahid
Is it just me or the expected answers for the subtractiona and division is
wrong in the sample main program?
As Prof Harder said: "The requirements for minus and divide suggest that
s.minus(r) and s.divide(r) should calculate r - s and r / s."
s.minus (r) = r - s = 1/2 - 2/3 = -1/6
s.divide (r) = r/s = 1/2 / 2/3 = 4/6
Post by Douglas Harder
I like the modification. Added to the specification.
Douglas
Post by Calvin Cheung
Slightly modified version to print out a message if actually the test ran.
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" );
Post by Calvin Cheung
else if ( q.getDenominator() != 6 )
throw new RuntimeException( "Wrong denominator: expecting
6" );
else System.out.println("Subtraction test successful.");
q = s.divide( r );
if ( q.getNumerator() != 4 )
throw new RuntimeException( "Wrong numerator: expecting
4" );
Post by Calvin Cheung
else if ( q.getDenominator() != 3 )
throw new RuntimeException( "Wrong denominator: expecting
3" );
else System.out.println("Division test successful.");
}
Calvin
Post by David I. Smith
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" );
Post by Calvin Cheung
Post by David I. Smith
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" );
Post by Calvin Cheung
Post by David I. Smith
if ( q.getDenominator() != 3 )
throw new RuntimeException( "Wrong denominator: expecting
3" );
}
Adam Bertrand
2005-01-24 06:09:01 UTC
Permalink
s.minus(r) == s-r
s.divide(r) == s/r

We've been over that about 10 times already...
it is equivalent to r-s which is 1/2-2/3=-1/6 so should it be expecting
a -1 instead of a 1?
For division
r/s = (1/2) / (2/3) so should the solution be 3/4?
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" );
}
Continue reading on narkive:
Loading...