/home/caleb/ASDV-Java/Semester 2/Assignments/lab2_CalebFontenot/src/main/java/com/calebfontenot/lab5_calebfontenot/QuadraticEquation.java
/*
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
 */
package com.calebfontenot.lab5_calebfontenot;

/**
 *
 * @author caleb
 */
public class QuadraticEquation {

    private double a;
    private double b;
    private double c;

    public QuadraticEquation(double a, double b, double c)
    {
        this.a = a;
        this.b = b;
        this.c = c;
    }

    public double getDiscriminant()
    {
        return b * b - 4 * a * c;
    }

    public double getRoot1()
    {
        if (getDiscriminant() < 0) {
            return -88888888;
        }
        return (b + Math.sqrt(b * b - 4 * a * c)) / (2 * a);
    }
        

    public double getRoot2()
    {
        if (getDiscriminant() < 0) {
            return -88888888;
        }
        return (-b + Math.sqrt(b * b - 4 * a * c)) / (2 * a);

        //return getDiscriminant() < 0 ? 0
        //       : ((-b) + Math.sqrt(Math.pow(b, 2) - 4 * a * c)) / (2 * a);
    }

    @Override
    public String toString()
    {
        return "QuadraticEquation{" + "a=" + a + ", b=" + b + ", c=" + c + '}';
    }

    /**
     * Get the value of b
     *
     * @return the value of b
     */
    public double getB()
    {
        return b;
    }

    /**
     * Get the value of c
     *
     * @return the value of c
     */
    public double getC()
    {
        return c;
    }

    /**
     * Get the value of a
     *
     * @return the value of a
     */
    public double getA()
    {
        return a;
    }

    public static void main(String[] args)
    {
        QuadraticEquation eq1 = new QuadraticEquation(1, -4, 4);
        System.out.println(eq1);
        System.out.println(eq1.getRoot1());
        System.out.println(eq1.getRoot2());
    }
}