Discussion:
Negative Degrees
(too old to reply)
Nahid
2005-02-09 05:21:56 UTC
Permalink
Polynomial x = new PolynomialAsArray( );

//given the above polynomial:

System.out.println(x.getCoefficient(5)); // should print out 0/1

//but how about the following case?

System.out.println(x.getCoefficient(-5));
// should it print out 0/1 or should it throw an exception?
David I. Smith
2005-02-09 14:33:27 UTC
Permalink
Looking at the course website, and the project specification it states
that we should return 0/1

-----ECE 250 Website Quote-----
Rational getCoefficient(int i)
This method returns the coefficient associated with the power i. If
i is negative or greater than the degree of the polynomial, the zero
rational should be returned. This must run in O(1) time.
-----End ECE 250 Website Quote-----
Post by Nahid
Polynomial x = new PolynomialAsArray( );
System.out.println(x.getCoefficient(5)); // should print out 0/1
//but how about the following case?
System.out.println(x.getCoefficient(-5));
// should it print out 0/1 or should it throw an exception?
Adam Bertrand
2005-02-09 17:57:46 UTC
Permalink
What he said,

The specs say to throw an exception when SETTING a coefficient of a
negative power.

ie x.setCoefficient(-5, new Rational(y, z)); should throw something.

Adam
Post by David I. Smith
Looking at the course website, and the project specification it states
that we should return 0/1
-----ECE 250 Website Quote-----
Rational getCoefficient(int i)
This method returns the coefficient associated with the power i. If
i is negative or greater than the degree of the polynomial, the zero
rational should be returned. This must run in O(1) time.
-----End ECE 250 Website Quote-----
Post by Nahid
Polynomial x = new PolynomialAsArray( );
System.out.println(x.getCoefficient(5)); // should print out 0/1
//but how about the following case?
System.out.println(x.getCoefficient(-5));
// should it print out 0/1 or should it throw an exception?
Jimmy XU
2005-02-09 18:11:11 UTC
Permalink
Yes, thanks
Post by Adam Bertrand
What he said,
The specs say to throw an exception when SETTING a coefficient of a
negative power.
ie x.setCoefficient(-5, new Rational(y, z)); should throw something.
Adam
Post by David I. Smith
Looking at the course website, and the project specification it states
that we should return 0/1
-----ECE 250 Website Quote-----
Rational getCoefficient(int i)
This method returns the coefficient associated with the power i. If i
is negative or greater than the degree of the polynomial, the zero
rational should be returned. This must run in O(1) time.
-----End ECE 250 Website Quote-----
Post by Nahid
Polynomial x = new PolynomialAsArray( );
System.out.println(x.getCoefficient(5)); // should print out 0/1
//but how about the following case?
System.out.println(x.getCoefficient(-5));
// should it print out 0/1 or should it throw an exception?
Continue reading on narkive:
Loading...