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;
}
我新上該這樣做面向對象的程序與要求用戶 輸入。我知道我有很多錯誤。我需要如何使我的 方法工作的幫助
程序:要求用戶輸入一個標記並顯示結果。如果廣告-BC = 0 報告`方程無解
錯誤:!=沒有在布爾定義的方程無解 不能從字符串轉換爲double,我已經試過字符串不能 化妝這行得通。異常在線程「主要」 java.lang.Error的:未解決 編譯問題:信息getX不能得到解決或無法在現場 的getY不能得到解決或無法在現場
'我知道我有很多錯誤'他們是什麼? 「如何讓我的方法奏效」現在什麼都行不通?儘量做到儘可能具體。 – amit
我可以知道爲什麼'this.setA(this.a)'是爲了? –
1.'getY()'被註釋掉2.如果'Linear'類在另一個文件中,它應該編譯並且3. Henry在下面寫下什麼 – alfasin