So this is what i dit. Declared three classes: Main Term Polynom
So in Polynom i try to call a "plus" method:
i tried this:
public Polynom add(Polynom pol){
Polynom res = new Polynom("",0);
Term tox = new Term(0,0);
for(Term p : Polynom){
for(Term other : pol.Polynom ){
if(p.getDeg()==other.getDeg()){
tox.setCoef(p.getCoef()+ other.getCoef());
tox.setDeg(p.getDeg());
}
res.addTerm(tox);
}
}
return res;
}
And I am facing a problem : I reffer to an object this and iam getting into an other object which is a this too. So when i try to add two polynoms I have wrong results.
Is there a good method for adding two Polynoms ?
private ArrayList<Term> Polynom = new ArrayList<Term>();
private String name;
private double number;
And the Term is :
public class Term {
private int deg;
private double coef;
}