I wrote a program to solve quadratics and now I'm trying to add GUI so I don't have to use the console for entering info.
Here is my code:
import java.util.*;
import java.awt.*;
public class MainClass {
public static void main (String [] args)
{
//Initialize
Scanner in = new Scanner(System.in);
//Frame aFrame = new Frame("Quadratic Equation Solver");
//aFrame.setSize(400, 100);
//aFrame.setVisible(true);
//Initiate Variables
double a, b, c;
//User input
System.out.print("Pease enter a: ");
//aFrame.add(new TextField("Pease enter a: "));
a = in.nextDouble();
System.out.print("Pease enter b: ");
//aFrame.add(new TextField("Pease enter b: "));
b = in.nextDouble();
System.out.print("Pease enter c: ");
//aFrame.add(new TextField("Pease enter c: "));
c = in.nextDouble();
//NaN Fix
if(b*b - 4 * a * c < 0)
{
System.out.println("Divide by Zero Error");
}else{
//Calculate
double num1 = (-b + (Math.sqrt((b*b) - 4 * a * c))) / (2 * a);
double num2 = (-b - (Math.sqrt((b*b) - 4 * a * c))) / (2 * a);
//Display
System.out.println("The answers are: " + num1 + " and " + num2);
//aFrame.add(new TextField("The answers are: " + num1 + " and " + num2));
}
}
}