我一直在努力学习我的课程。我必须为线性方程创建一个对象类。然后,我必须有一个获取x和y值的测试程序。没有什么是强调的,看着我书中的例子,我只是没有看到我出错的地方。有人可以帮我弄清楚如何解决它?我的结果如下:
“等式没有解决方案
方程没有解决方案
x是NaN,y是NaN“
我的对象类是:
private double a, b, c, d, e, f;
private double x, y;
public LinearEquation() {
}
LinearEquation(double a, double b, double c, double d, double e, double f) {
}
public boolean isSolvable() {
if (((a * d) - (b * c)) == 0) {
System.out.println("The equation has no solution");
return false;
}
return true;
}
public double getX() {
if (isSolvable());
x = (((e * d) - (b * f)) / ((a * d) - (b * c)));
return x;
}
public double getY() {
if (isSolvable());
y = (((a * f) - (e * c)) / ((a * d) - (b * c)));
return y; }
我的测试类是:
public static void main(String[] args) {
double a = 9.0;
double b = 4.0;
double c = 3.0;
double d = -5.0;
double e = -6.0;
double f = -21.0;
LinearEquation numberSet = new LinearEquation(a, b, c, d, e, f);
double xValue = numberSet.getX();
double yValue = numberSet.getY();
System.out.println("x is " + xValue + " and y is " + yValue); }