Java project
Java project
JOptionPane;
public class quadratic { public static void main(String[] args)
{ double a = 0, b = 0, c = 0;
// Validate coefficient 'a' is not zero
while (true) { try
{
String inputA = JOptionPane.showInputDialog(null, "Enter coefficient a (must not be 0):");
if (inputA == null) return;
// User cancelled a =
a= Double.parseDouble(inputA);
if (a == 0) {
System.out.println("Coefficient 'a' cannot be zero.");
} else {
break;
}
} catch (NumberFormatException e)
{ System.out.println( "Please enter a valid number for a.");
}
}
// Get coefficient b
while (true)
{ try
{ String inputB = JOptionPane.showInputDialog(null, "Enter coefficient b:");
if (inputB == null) return;
b = Double.parseDouble(inputB);
break;
} catch (NumberFormatException e)
{ System.out.println("Please enter a valid number for b.");
}
}
// Get constant c
while (true)
{ try
{ String inputC = JOptionPane.showInputDialog(null, "Enter constant c:");
if (inputC == null) return;
c = Double.parseDouble(inputC);
break;
} catch (NumberFormatException e) {