Guest User

Untitled

a guest
Apr 23rd, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.50 KB | None | 0 0
  1. public class Equation {
  2.  
  3. public static double a;
  4. public static double b;
  5. public static double c;
  6.  
  7. public int kol;
  8.  
  9. public int kolkorni() {
  10. if (a != 0) {
  11. if (b * b - 4 * a * c > 0) {
  12. kol = 2;
  13. }
  14. }
  15. if ((a == 0) && (b != 0) && (c != 0)) {
  16. kol = 1;
  17. }
  18. }
  19. }
  20.  
  21. void printA(){
  22. System.out.println(a);
  23. }
  24.  
  25. public static double a;
  26. public static double b;
  27. public static double c;
  28.  
  29. public class Equation {
  30.  
  31. private double a;
  32. private double b;
  33. private double c;
  34.  
  35. public Equation(double a, double b, double c){
  36. this.set(double a, double b, double c);
  37. }
  38.  
  39. public void set(double a, double b, double c) {
  40. this.a = a;
  41. this.b = b;
  42. this.c = c;
  43. }
  44.  
  45. public double getA() {
  46. return a;
  47. }
  48.  
  49. public double getB() {
  50. return b;
  51. }
  52.  
  53. public double getC() {
  54. return c;
  55. }
  56.  
  57. public int resultsNuber() {
  58. if (isQuadratic()) {
  59. double discriminant = this.getDiscriminant();
  60. if (discriminant > 0) {
  61. return 2;
  62. } else if (discriminant == 0.0) {
  63. return 1;
  64. } else {
  65. return 0;
  66. }
  67. }
  68.  
  69. if (isLinear()) {
  70. return 1;
  71. }
  72.  
  73. return Integer.MAX_VALUE;
  74. }
  75.  
  76. private boolean isQuadratic() {
  77. return a != 0;
  78. }
  79.  
  80. private boolean isLinear() {
  81. return (a == 0) && (b != 0) && (c != 0);
  82. }
  83.  
  84. private double getDiscriminant() {
  85. return b*b - 4*a*c;
  86. }
  87.  
  88. public void toString() {
  89. return "" + a + "*x^2 + " + b +"*x + " + c + " = 0";
  90.  
  91. }
  92. }
  93.  
  94. public abstract class Equation {
  95. protected double static epsilon=0.0000001; //значение зависит от задачи
  96. protected double a;
  97. protected Equation(double a) {this.a=a;}
  98. protected boolean isZero(double x) {
  99. if(Math.abs(x) <= epsilon)
  100. return true;
  101. return false;
  102. }
  103. public abstract int getNumberOfRoots();
  104. }
  105.  
  106. public class LinearEquation extends Equation {
  107. protected double b;
  108. public LinearEquation(double a, double b) {super(a); this.b=b;}
  109. public int getNumberOfRoots() {
  110. if(this.isZero(b)
  111. return 0;
  112. return 1;
  113. }
  114.  
  115. public class QuadraticEquation extends LinearEquation {
  116. protected double c;
  117. public LinearEquation(double a, double b, double c) {super(a, b); this.c=c;}
  118. public int getNumberOfRoots() {
  119. //blah-blah
  120. }
  121. }
Add Comment
Please, Sign In to add comment