|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.ObjectTerm
public class Term
Class to hold one term of a polynomial over x. Both coefficient and exponent are ints.
| Constructor Summary | |
|---|---|
Term(int coef,
int expon)
Constructor for objects of class Term. |
|
Term(Term t)
Constructor for objects of class Term. |
|
| Method Summary | |
|---|---|
void |
combine(Term term)
Combines this term and the argument term back into this term. |
int |
compareTo(Term term)
Imposes "natural ordering" on Term objects. |
boolean |
equals(java.lang.Object obj)
Compare this object to the specified object. |
int |
getCoefficient()
Fetch coefficient value. |
int |
getExponent()
Fetch exponent value. |
static Term |
product(Term a,
Term b)
Returns a new Term formed by the product of two Terms. |
void |
setCoefficient(int coef)
Replace coefficient value with new one. |
static Term |
sum(Term a,
Term b)
Returns a new Term formed by the sum of two Terms. |
java.lang.String |
toString()
Returns a String representing this term, with fully signed coefficient and using nothing for multiplication and ^ for exponentiation. |
| Methods inherited from class java.lang.Object |
|---|
getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public Term(int coef,
int expon)
coef * x expon
Postconditions:
getCoefficient() == coef
getExponent() == expon
coef - the coefficient valueexpon - the exponent valuepublic Term(Term t)
coef * x expon
Postconditions:
getCoefficient() == t.getCoefficient()
getExponent() == t.getExponent()
t - Term whose contents will be copied into the new one| Method Detail |
|---|
public int getCoefficient()
public int getExponent()
public void setCoefficient(int coef)
Postcondition: getCoefficient() == coef
coef - the new coefficient value.public boolean equals(java.lang.Object obj)
equals in class java.lang.Objectobj - The object to compare with.
public int compareTo(Term term)
throws java.lang.IllegalArgumentException
Precondition: term != null
compareTo in interface java.lang.Comparable<Term>term - The Term against which this Term is compared
java.lang.IllegalArgumentException - if the argument is null.
public void combine(Term term)
throws java.lang.IllegalArgumentException
Precondition: term != null && getExponent() == term.getExponent()
Postcondition: getCoefficient() == OLD.getCoefficient() + term.getCoefficient()
term - the term to be folded into this term.
java.lang.IllegalArgumentException - if the argument is null or terms have different exponents.
public static Term sum(Term a,
Term b)
throws java.lang.IllegalArgumentException
Precondition: a != null && b != null && a.getExponent() == b.getExponent()
a - first term in the sum.b - second term in the sum.
java.lang.IllegalArgumentException - if the argument is null or terms have different exponents.
public static Term product(Term a,
Term b)
throws java.lang.IllegalArgumentException
Precondition: a != null && b != null
a - first term in the product.b - second term in the product.
java.lang.IllegalArgumentException - if the argument is null.public java.lang.String toString()
toString in class java.lang.Object
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||