TXT

experment6

By Bobby Chavez,2014-03-25 18:40
11 views 0
experment6

class SquareEquation {

     double a, b;

     static double c;

     double x1, x2;

     public SquareEquation(double a, double b, double c) {

     this.a = a;

     this.b = b;

     SquareEquation.c = c;

     }

     void setCoefficient(double a, double b, double c) {

     this.a = a;

     this.b = b;

     SquareEquation.c = c;

     }

     void getCoefficient(double a, double b, double c) {

     this.a = a;

     this.b = b;

     SquareEquation.c = c;

     }

     public void getRoots() {

     if (a != 0) {

     System.out.println("ÊÇÒ?Ôª?þ?Î???Ì");

     double disk = b * b - 4 * a * c;

     if (disk >= 0) {

     x1 = (-b + Math.sqrt(disk) / (2 * a));

     x2 = (-b - Math.sqrt(disk) / (2 * a));

     System.out.println("Ò?Ôª?þ?Î???̵Ä?ù :" + "x1=" + x1 +

    " " + "x2="

     + x2);

     } else {

     System.out.println("Ò?Ôª?þ?Î???ÌÃ?ÓÐʵ?ù");

     }

     } else {

     System.out.println("??ÊÇÒ?Ôª?þ?Î???Ì");

     }

     }

    }

public class experiment6 {

     public static void main(String[] args) {

     SquareEquation equation = new SquareEquation(4, 5, 1);

     equation.getRoots();

     equation.setCoefficient(-3, 4, 5);

     equation.getRoots();

     }

    }

Report this document

For any questions or suggestions please email
cust-service@docsford.com