-
Notifications
You must be signed in to change notification settings - Fork 0
/
Polinomio.java
46 lines (43 loc) · 1.18 KB
/
Polinomio.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/**
* Esta clase esta encargada de crear el polinomio adjuntado terminos
*
* @author Cristhian Adal Garcia Hdez.
* @version 1.5.5
*/
public class Polinomio
{
// instance variables - replace the example below with your own
private Termino termino[];
private int dos=0;
private String cadena = "\0";
public Polinomio(int grado)
{
termino = new Termino[grado+1];
}
public void agregaTermino(Termino term)
{
termino[dos]=term;
dos++;
}
public double evalua(double x)
{
double evaluar = 0;
for (int index = 0; index < termino.length; index++)
{
if( termino[index] != null )
evaluar += termino[index].evalua(x);
}
return evaluar;
}
public String toString()
{
for(int gis = 0; gis<dos; gis++ )
{
if ( termino[gis].getCoeficiente() < 0 )
cadena = ( cadena + termino[gis].getCoeficiente() + "x^ " + termino[gis].getExponente() );
else
cadena = (cadena + "+" + termino[gis].getCoeficiente() + "x^ " + termino[gis].getExponente() );
}
return cadena;
}
}