//Shawnak Shivakumar   
//
//December 7, 2020
//
//This program solves quadratic equations and gives both roots.
//
//VIEWERS - COPY AFTER THIS LINE TILL THE END AND PASTE IT HERE: 
//https://www.onlinegdb.com/. Select Java As the language and click run! Enter your //numbers into the console and enjoy!

import java.util.*;
public class Main {
  public static void main(String [] args){
    Scanner scan = new Scanner (System.in);
System.out.println("Enter 1 (or any number aside from 2) if you want to run the Quadratic Equation Solver Program, or 2 is you don't!");
int ans = scan.nextInt();
while (ans != 2) {
System.out.println("Welcome To The Quadratic Equation Solver Program!");
System.out.println("Please enter a, b, c in the quadratic ax^2+bx+c=0");
System.out.println("Please enter a: ");
float a = scan.nextFloat();
System.out.println("Great! Please enter b: ");
float b = scan.nextFloat();
System.out.println("Great! Please enter c: ");
float c = scan.nextFloat();
//quadratic formula calculates both roots
float discriminant = (float) Math.pow(b,2) - 4*a*c;
float abs = (float) Math.abs(Math.pow(b,2) - 4*a*c);
int sqrt = (int) Math.pow(abs, 0.5);
if (discriminant < 0) {
    System.out.println("The answers are imaginary.");
    if (b != 0) {
System.out.println("The First Imaginary Answer: " + -b + "+" + sqrt + "i" + "/" + 2*a + " or exactly " + -b + "+" + "√" + discriminant + "/" + 2*a);
System.out.println("The Second Imaginary Answer: " + -b + "-" + sqrt + "i" + "/" + 2*a + " or exactly " + -b + "-" + "√" + discriminant + "/" + 2*a);
}
else {
System.out.println("The First Imaginary Answer: +" + sqrt + "i" + "/" + 2*a + " or exactly +" + "√" + discriminant + "/" + 2*a);
System.out.println("The Second Imaginary Answer: -" + sqrt + "i" + "/" + 2*a + " or exactly -" + "√" + discriminant + "/" + 2*a);
}
}
else if (a != 0) {   
double x = (-b+ Math.pow(Math.pow(b,2) - 4*a*c,0.5))/(2*a);
double y = (-b- Math.pow(Math.pow(b,2) - 4*a*c,0.5))/(2*a);
System.out.println("\nThe First Answer is: " + x);
System.out.println("\nThe Second Answer is: " + y);
}
else if (a == 0) {
    if (b != 0) {
    float x = -c/b;
    System.out.println("The Only Answer Is: " + x);
    }
    else {
        if (c != 0) {
            System.out.println("This equation is false, NO SOLUTIONS.");
        }
        else if (c == 0) {
            System.out.println("This equation is true, Infinite Solutions");
        }
    }
}
System.out.println("Do you want to run again? Please press 1 if yes, and 2 if No.");
ans = scan.nextInt();
}
System.out.println("Thank you for checking out the Quadratic Equation Solver Program! Press enter to exit the console.");
}
}