Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. public class Quad2
  2. {
  3. private double a;
  4. private double b;
  5. private double c;
  6. public Quad2 (double aa, double bb, double cc)
  7. {
  8. a = aa;
  9. b = bb;
  10. c = cc;
  11. }
  12.  
  13.  
  14. public String getNumSolns()
  15. {
  16. if((b*b)-(4*a*c) > 0)
  17. {
  18. return "Two real solutions";
  19. }
  20. else if((b*b)-(4*a*c) == 0)
  21. {
  22. return "One real solution";
  23. }
  24. else
  25. {
  26. return "Complex Solutions";
  27. }
  28. }
  29.  
  30.  
  31. public void getSolns()
  32. {
  33. if((b*b)-4*a*c > 0)
  34. {
  35. System.out.println(getSolution1() + " " + getSolution2());
  36. }
  37. else if((b*b)-4*a*c == 0)
  38. {
  39. System.out.println(getSolution1());
  40. }
  41. else
  42. {
  43. System.out.println(-b / (2*a) + "+" + (Math.sqrt(Math.abs((b*b)-(4*a*c)) ) ) / (2*a) + "i");
  44. System.out.println(-b / (2*a) + "-" + (Math.sqrt(Math.abs((b*b)-(4*a*c)) ) ) / (2*a) + "i");
  45. }
  46. }
  47.  
  48.  
  49.  
  50.  
  51. public double getSolution1()
  52. {
  53. return (-b + Math.sqrt((b*b)-4*a*c)) / (2*a);
  54.  
  55.  
  56. }
  57.  
  58. public double getSolution2()
  59. {
  60. return (-b - Math.sqrt((b*b)-4*a*c)) / (2*a);
  61. }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement