I'm trying to make a polynomial operator (sum, rest, multiplication and division of two or more polynomials). The code must be in Java and using linked lists.
I was wondering how do calculators or how to validate whether a polynomial is valid or not. I want to construct a polynomial from a String, but I don't know if there is another class that can ease things.
This is a homework assignment so I'm not asking for complete code, just something that points me in a good direction.
There are two classes, one for nodes (named Monomio) and one for the list (named Polinomio, is the sum of monomials). The node class has
Monomio siguienteMonomio; // The next monomial
int exponente; // I don't know how to say this in English, maybe power
int coeficiente; // The coefficient
// A bunch of methods, to sum, multiply etc.
and the list class has
Monomio primerMonomio; //First Monomial
Monomio ultimoMonomio; //Last Monomial
// A bunch of methods, like organize the polynomial by the power, multiply, sum, etc.
Now I need a constructor like this.
public Polinomio(String polinomio){
enter code here
}
The user should enter something like this:
10x^2 - 7x + 9
So the constructor makes a list of three nodes:
//First node
int coeficiente = 10;
int exponente = 2;
Monomio siguienteMonomio = //secondNode
//Second node
int coeficiente = -7;
int exponente = 1;
Monomio siguienteMonomio = //thirdNode
//Third node
int coeficiente = 9;
int exponente = 0;
Monomio siguienteMonomio = null;
So, any ideas of how to make this? I can simply track specific characters (+ - ^ x). But that would be long and maybe there is a better way to do.