Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Equation {
- public static double a;
- public static double b;
- public static double c;
- public int kol;
- public int kolkorni() {
- if (a != 0) {
- if (b * b - 4 * a * c > 0) {
- kol = 2;
- }
- }
- if ((a == 0) && (b != 0) && (c != 0)) {
- kol = 1;
- }
- }
- }
- void printA(){
- System.out.println(a);
- }
- public static double a;
- public static double b;
- public static double c;
- public class Equation {
- private double a;
- private double b;
- private double c;
- public Equation(double a, double b, double c){
- this.set(double a, double b, double c);
- }
- public void set(double a, double b, double c) {
- this.a = a;
- this.b = b;
- this.c = c;
- }
- public double getA() {
- return a;
- }
- public double getB() {
- return b;
- }
- public double getC() {
- return c;
- }
- public int resultsNuber() {
- if (isQuadratic()) {
- double discriminant = this.getDiscriminant();
- if (discriminant > 0) {
- return 2;
- } else if (discriminant == 0.0) {
- return 1;
- } else {
- return 0;
- }
- }
- if (isLinear()) {
- return 1;
- }
- return Integer.MAX_VALUE;
- }
- private boolean isQuadratic() {
- return a != 0;
- }
- private boolean isLinear() {
- return (a == 0) && (b != 0) && (c != 0);
- }
- private double getDiscriminant() {
- return b*b - 4*a*c;
- }
- public void toString() {
- return "" + a + "*x^2 + " + b +"*x + " + c + " = 0";
- }
- }
- public abstract class Equation {
- protected double static epsilon=0.0000001; //значение зависит от задачи
- protected double a;
- protected Equation(double a) {this.a=a;}
- protected boolean isZero(double x) {
- if(Math.abs(x) <= epsilon)
- return true;
- return false;
- }
- public abstract int getNumberOfRoots();
- }
- public class LinearEquation extends Equation {
- protected double b;
- public LinearEquation(double a, double b) {super(a); this.b=b;}
- public int getNumberOfRoots() {
- if(this.isZero(b)
- return 0;
- return 1;
- }
- public class QuadraticEquation extends LinearEquation {
- protected double c;
- public LinearEquation(double a, double b, double c) {super(a, b); this.c=c;}
- public int getNumberOfRoots() {
- //blah-blah
- }
- }
Add Comment
Please, Sign In to add comment