50 lines
1.0 KiB
Java
50 lines
1.0 KiB
Java
package no.birkett.kiwi;
|
|
|
|
/**
|
|
* Created by alex on 30/01/15.
|
|
*/
|
|
public class Term implements ExpressionConvertible {
|
|
|
|
private Variable variable;
|
|
double coefficient;
|
|
|
|
public Term(Variable variable, double coefficient) {
|
|
this.variable = variable;
|
|
this.coefficient = coefficient;
|
|
}
|
|
|
|
public Term(Variable variable) {
|
|
this(variable, 1.0);
|
|
}
|
|
|
|
public Variable getVariable() {
|
|
return variable;
|
|
}
|
|
|
|
public void setVariable(Variable variable) {
|
|
this.variable = variable;
|
|
}
|
|
|
|
public double getCoefficient() {
|
|
return coefficient;
|
|
}
|
|
|
|
public void setCoefficient(double coefficient) {
|
|
this.coefficient = coefficient;
|
|
}
|
|
|
|
public double getValue() {
|
|
return coefficient * variable.getValue();
|
|
}
|
|
|
|
@Override
|
|
public Expression toExpression() {
|
|
return new Expression(this);
|
|
}
|
|
|
|
@Override
|
|
public String toString() {
|
|
return "variable: (" + variable + ") coefficient: " + coefficient;
|
|
}
|
|
}
|