import java.util.ArrayList;

public class Polynome {
	private ArrayList<Double> coefficients = new ArrayList();;
	
	public Polynome (double c, int d) {	
		for(int i = 0; i < coefficients.size();++i) {
			coefficients.add(0.);
		}
		coefficients.set(d, c);
		
	}
	
	public Polynome(Polynome p) {
		coefficients = new ArrayList<>(p.coefficients);
	}
	
	public Polynome () {
		 new Polynome(0.,0);
	}
	
	public Polynome (double c) {
		new Polynome(c, 0);
	}
	
	public double evaluer (double x) {
		double valeur = 0.;
		for(int i = 0; i < coefficients.size();++i) {
			valeur+=coefficients.get(i) * Math.pow(x,i);
		}		
		return valeur;
	}
	
	public Polynome ajouter(Polynome p) {
		Polynome somme = new Polynome();
		for(int i = 0; i < p.coefficients.size(); ++i) {
			somme.coefficients.set(i,p.coefficients.get(i)+this.coefficients.get(i));
		}
		return somme;
	}
	
	public Polynome dériver(Polynome p) {
		Polynome dérivée = new Polynome();
		dérivée = p;
		dérivée.coefficients.remove(0);
		return dérivée;
	}
	
	public String toString() {
		String s = new String();
		for(Integer i = coefficients.size()-1; i <= 0 ;--i) {
			s+= coefficients.get(i).toString() + "x^" + i.toString() + "+"; 
		}
		return s;
	}
}
