Guest User

Untitled

a guest
Feb 17th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. import static java.lang.Math.*;
  2.  
  3. public class Polynomial {
  4.  
  5. private double a1, b1, c1;
  6. private double a2, b2, c2;
  7.  
  8. private Polynomial(double a1, double b1, double c1) {
  9. this.a1 = a1;
  10. this.b1 = b1;
  11. this.c1 = c1;
  12. }
  13.  
  14. /*private Polynom2(double a2, double b2, double c2) {
  15. this.a2 = a2;
  16. this.b2 = b2;
  17. this.c2 = c2;
  18. }*/
  19.  
  20. private void addPolynom() {
  21. double a3 = a1 + a2;
  22. double b3 = b1 + b2;
  23. double c3 = c1 + c2;
  24.  
  25. }
  26.  
  27.  
  28. private void subPolynom() {
  29. double a3 = a1 - a2;
  30. double b3 = b1 - b2;
  31. double c3 = c1 - c2;
  32. }
  33.  
  34. private void nullPolynom(){
  35. double d = 4 * b1 - a1 * c1;
  36. double x1 = ((-b1 + sqrt(d)) / 2) * a1;
  37. double x0 = ((-b1 - sqrt(d)) / 2) * a1;
  38. System.out.print("x0= "+x0+ " x1="+x1);
  39.  
  40. }
  41. public String toString(){
  42. return "f(x1)= " + a1 +"x^2 + "+ b1 +"x + "+ c1;
  43. }
  44. public static void main(String[] args) {
  45. Polynomial polynom = new Polynomial(2.0, -5.0, 9.0);
  46. Polynomial polynom1 = new Polynomial( -5.0, 8.0, -3.0);
  47. System.out.println("f(x)=" +polynom.a1+"x^2 "+polynom.b1+"x + "+polynom.c1);
  48. System.out.print(polynom);
  49. polynom.addPolynom();
  50. System.out.println(polynom);
  51. polynom.subPolynom();
  52. System.out.println(polynom);
  53. polynom.nullPolynom();
  54. }
  55. }
Add Comment
Please, Sign In to add comment