import java.util.Scanner;
public class LinearDrive {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.print("Enter value for a: ");
double a= in.nextDouble();
System.out.print("Enter value for b: ");
double b= in.nextDouble();
System.out.print("Enter value for c: ");
double c= in.nextDouble();
System.out.print("Enter value for d: ");
double d= in.nextDouble();
System.out.print("Enter value for e: ");
double e= in.nextDouble();
System.out.print("Enter value for f: ");
double f= in.nextDouble();
Linear linear = new Linear(a,b,c,d,e,f);
System.out.println("X= "+ linear.getX);
System.out.println("Y= "+ linear.getY);
}
}
public class Linear {
private double a;
private double b;
private double c;
private double d;
private double e;
private double f;
public Linear(double a, double b, double c, double d, double e, double f) {
this.setA(a);
this.setB(b);
this.setC(c);
this.setD(d);
this.setE(e);
this.setF(f);
}
public Linear(){
}
public double getA() {
return a;
}
public void setA(double a) {
this.a = a;
}
public double getB() {
return b;
}
public void setB(double b) {
this.b = b;
}
public double getC() {
return c;
}
public void setC(double c) {
this.c = c;
}
public double getD() {
return d;
}
public void setD(double d) {
this.d = d;
}
public double getE() {
return e;
}
public void setE(double e) {
this.e = e;
}
public double getF() {
return f;
}
public void setF(double f) {
this.f = f;
}
public boolean isSolvable(){
boolean isSolvable= ((a*d) - (b*c));
if (isSolvable!=0){
isSolvable = true;
}
return isSolvable;
}
public double otherCase(){
double otherCase=((a*d) - (b*c));
if(otherCase==0){
otherCase="The equation has no solution";
}
}
public double getX(){
double x = ((this.e*this.d) - (this.b*this.f)) / ((this.a*this.d) - (this.b*this.c));
return x;
}
public double getY(){
double y= ((a*f) - (e*c)) / ((a*d) - (b*c));
return y;
}
}
我是关于通过询问用户进行面向对象程序的新手 用于输入。我知道我有很多错误。我需要有关如何制作我的帮助 方法工作
程序:要求用户输入b c d e f并显示结果。如果 ad-bc=0 报告"方程没有解
错误:!= 未在布尔值上定义 方程没有解 无法从字符串转换为双精度,我试过字符串不能 让它工作。线程"main"java.lang 中的异常:未解决 编译问题:getX 无法解析或不是字段 getY 无法解析或不是字段
此行
this.setA(this.a);
应该是
this.setA(a);
否则,getX
和getY
方法似乎都可以。要调用它们,您需要添加 (),如下所示:
System.out.println("X= "+ linear.getX());
要检查系统是否可以解决,您可以使用这样的方法:
public boolean isSolvable() {
return Math.abs(a*b - c*d) > 1e-10;
}
请注意,切勿将浮点数与 ==
进行比较。由于舍入误差,计算结果几乎从不精确。上面的代码使用 10-10 的间隔来检查零行列式。