package lab2;

/**
 * Quadratic Equation lab2 exercise 5
 * @author martin
Exercice

Créez la classe EquationQuadratique avec méthodes les hasSolution(), premiereSolution(),
deuxiemeSolution(). La fonction hasSolution() retournera vrai si l’équation a des solutions dans les
valeurs réelles et faux si elle n’a pas.
 */

public class QuadraticEquation {
	/*Properties*/
	private final int _a,
	                  _b,
	                  _c;

	/*constructor*/
	/**
	 * constructor for ax² + bx + c
	 * @param a as int
	 * @param b as int
	 * @param c as int
	 * to simple for static factory
	 */
	public QuadraticEquation(int a, int b, int c){
		_a = a;
		_b = b;
		_c = c;
	}

	/*getter*/
	/**
	 * @return a
	 */
	public int a(){
		return _a;
	}

	/**
	 * @return b
	 */
	public int b(){
		return _b;
	}

	/**
	 * @return c
	 */
	public int c(){
		return _c;
	}

	/*methode*/
	/**
	 * @return true if their is a solution
	 */
	public boolean hasSolution(){
		return (_b*_b)-(4*_a*_c) >= 0;
	}

	/**
	 * @return first solution for ax² + bx + c = 0
	 */
	public double firstSolution(){
		return (-_b - Math.sqrt(4.0*_a*_c))/(2*_a);
	}

	/**
	 * @return second solution for ax² + bx + c = 0
	 */
	public double secondSolution(){
		return (-_b + Math.sqrt(4.0*_a*_c))/(2*_a);
	}
}
