package homework04;
public class Function {
private int a;
private int b;
private int c;
private double x1;
private double x2;
public Function(int a ,int b,int c)
{
this.a = a;
this.b = b;
this.c = c;
}
public double getD(){
return (this.b*this.b-4*this.a*this.c);
}
public int getA() {
return a;
}
public void setA(int a) {
this.a = a;
}
public int getB() {
return b;
}
public void setB(int b) {
}
public int getC() {
return c;
}
public void setC(int c) {
this.c = c;
}
public double getX1() {
return x1;
}
public void setX1(double x1) {
this.x1 = x1;
}
public double getX2() {
return x2;
}
public void setX2(double x2) {
this.x2 = x2;
}
public void fun() throws Exception{
if(this.a != 0)
{
double m = this.getD();
if(m > 0)
{
x1 = (-this.b+Math.sqrt(m))/(2*this.a);
x2 = (-this.b-Math.sqrt(m))/(2*this.a);
System.out.println("此方程有两个不同的解");
}
if(m==0)
{
x1 = -this.b/(2*this.a);
System.out.println("此方程有两个相同的解");
}
if(m < 0)
{
Exception e1 = new Exception("方程无解");
throw e1;
}
}
else
{
Exception e2 = new Exception("二次项系数为0");
throw e2;
}
}
}