Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class EquationsMain {
- /**
- * @param args
- */
- public static void main(String[] args)
- {
- double a, b, c, vx, vy, xans1, xans2;
- Scanner i = new Scanner(System.in);
- boolean doAgain;
- do
- {
- doAgain=false;
- System.out.print("A value: ");
- a = i.nextDouble();
- i.nextLine();
- System.out.print("B value: ");
- b = i.nextDouble();
- i.nextLine();
- System.out.print("C value: ");
- c = i.nextDouble();
- i.nextLine();
- String e = "Equation: " + a + "x^2";
- if(b<0)
- {
- e += "" + b + "x";
- }
- else if(b>0)
- {
- e += "+" + b + "x";
- }
- if(c<0)
- {
- e += "" + c;
- }
- else if(c>0)
- {
- e += "+" + c;
- }
- e += "=0";
- System.out.println(e);
- String s = "Solution: ";
- xans1 = ((b*-1) + Math.sqrt((b*b)-4*a*c))/(2*a);
- xans2 = ((b*-1) - Math.sqrt((b*b)-4*a*c))/(2*a);
- vx=-(b)/(2*a);
- vy = a*(vx*vx) + b*vx + c;
- double b2 = b*b, a2 = a* -4;
- double discr = b2 + (a2*c);
- s+= xans1;
- if(xans1 != xans2)
- {
- s+= ", ";
- s+= xans2;
- }
- if(((b*b)-4*a*c) < 0)
- {
- System.out.println("There are no solutions.");
- }
- else
- {
- System.out.println(s + '\n' + "Time: " + (Math.sqrt(xans2)));
- }
- System.out.println("Exact answer: (" + -b + " +/- Sqrt(" + discr + ")) / " + (a*2));
- String v = "Vertex: (" + vx + ", " + vy + ")";
- System.out.println(v + "\nDiscriminant: " + discr);
- double x2=vx+1, x3=vx+2, y2, y3;
- y2 = a*(x2*x2) + b*x2 + c;
- y3 = a*(x3*x3) + b*x3 + c;
- System.out.println(" x | y ");
- System.out.println("-----------");
- System.out.println( x2+" | "+y2 );
- System.out.println( x3+" | "+y3 );
- boolean v1;
- do
- {
- System.out.print("Do another equation? ");
- String d = i.nextLine();
- String yn = d.charAt(0) + "";
- v1=true;
- if(yn.equalsIgnoreCase("y"))
- {
- doAgain=true;
- }
- else if(!(yn.equalsIgnoreCase("n")))
- {
- System.out.println("Please type YES or NO");
- v1=false;
- }
- }
- while(!v1);
- }
- while(doAgain);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment