QUADRATIC EQUATIONS
package quadraticequations; import [Link]; import [Link]; /** * * @author Sergie_Chingly */ public class QuadraticEquations { double a, b, c, d, e, f, g, h, i; boolean x; int r; public void solver1() { do { try { String aa = [Link]("Enter value of A"); a = [Link](aa); if (a == 0) { [Link](null, "A is an invalid input. Try again another value.", "Error!", JOptionPane.ERROR_MESSAGE); QuadraticEquations s = new QuadraticEquations(); s.solver1(); } else { String bb = [Link]("Enter the value of B"); b = [Link](bb); String cc = [Link]("Enter the value of C"); c = [Link](cc); if(b == 0) {
if(c == 0) { [Link](null , "The root is x = 0.", "Answer", JOptionPane.PLAIN_MESSAGE); } else if (c < 0) { d = -c/a; e = [Link](d); Formatter x = new Formatter(); [Link]("%.6f", e); [Link](null , "The root is x = " + [Link]() + "." , "Answer", JOptionPane.PLAIN_MESSAGE); } else if (c > 0) { d = c/a; e = [Link](d); Formatter z = new Formatter(); [Link]("%.6f", e); [Link](null , "The root is x = j" + [Link]() + ".", "Answer", JOptionPane.PLAIN_MESSAGE); } } if(c == 0) { if(b == 0) { [Link](null , "The root is x = 0.", "Answer", JOptionPane.PLAIN_MESSAGE); } else { [Link](null , "The root is x = " + -b/a + "." , "Answer", JOptionPane.PLAIN_MESSAGE); } } }
x = false; } catch(NumberFormatException e) { [Link](null, "Invalid value. Try again another value.", "Error!", JOptionPane.ERROR_MESSAGE); QuadraticEquations s = new QuadraticEquations(); s.solver1(); } } while( x ); if (a == 0 || b == 0 || c == 0){} else { d = b*b - 4*a*c; if (d == 0) { e = -b/(2*a); Formatter i = new Formatter(); [Link]("%.6f", e); [Link](null , "The root is x = " + [Link]() + "." , "Answer", JOptionPane.PLAIN_MESSAGE); } else if (d > 0) { f = [Link](d); g = (-b + f)/(2*a); h = (-b - f)/(2*a); Formatter l = new Formatter(); [Link]("%.6f", g); Formatter y = new Formatter(); [Link]("%.6f", h); [Link](null , "The roots are x1 = " + [Link]() + " and x2 = " + [Link]() +"." ,"Answer", JOptionPane.PLAIN_MESSAGE); } else if (d < 0) {
e = -d; f = [Link](e); g = -b/(2*a); h = f/(2*a); Formatter j = new Formatter(); [Link]("%.6f", g); Formatter o = new Formatter(); [Link]("%.6f", h); [Link](null , "The roots are x1 = " + [Link]() + " + j" + [Link]() + " and x2 = " + [Link]() + " - j" + [Link]() + ".", "Answer", JOptionPane.PLAIN_MESSAGE); } } } /** * @param args the command line arguments */ public static void main(String[] args) { [Link](null, "General form of a Quadratic Equation: Ax^2 + Bx + C = 0", "Hey!", JOptionPane.PLAIN_MESSAGE); QuadraticEquations s = new QuadraticEquations(); s.solver1();
ARRAY
package arrayjava; import [Link]; import [Link];
/** * * @author Sergie_Chingly */ public class ArrayJava { /** * @param args the command line arguments */ public static void main(String[] args) { Scanner scanner = new Scanner([Link]); int x; [Link]("Number of Array/s:"); x = [Link](); int[] array = new int[x]; for(int y = 0; y != x; y++) { [Link]("array[" + y + "]: " ); array[y] = [Link](); } { int total = 0; for(int z = 0; z != x; z++) { total += array[z]; } double average = total/[Link]; [Link]("\nSummation of Arrays: %d", total); [Link]("\nAverage of Arrays: %f", average); } int lowest = array[0]; for (int element : array) { if (element < lowest) lowest = element; }
int highest = array[0]; for (int value : array) { if (value > highest) highest = value; } [Link](array); [Link]("\nLowest Value: %d\n", lowest);
[Link]("Highest Value: %d\n", highest); { [Link]("\nArrays in Descending Order:" ); for(int i = [Link] - 1; i >= 0; i--) { [Link]( " " + array[i]); } [Link]("\nArrays in Ascending Order:" ); for(int i = 0; i < [Link]; i++) { [Link]( " " + array[i]); } } } }
Mindanao State University College of Engineering General Santos City
ES 84 JAVA PROGRAM
Quadratic Equation and Array
Submitted in Partial Fulfillment of the Requirements in ES 84: Numerical Methods - EE
School Year: 2012-2013, 2nd Semester MTH 7:30 9:00 a.m.
Submitted by:
Andres, Chingly Sergie P.
20 February 2013
OUTPUT
Quadratic Equation
Array