缺少牙套,但我从未错过 (Java)
Missing braces but I never missed it (Java)
当我输入“if conditional”时会发生这种情况。
很抱歉带来了满满的代码,但是我整天都在尝试找出问题所在,但我仍在寻找问题。
import javax.swing.JOptionPane;
class Accounting2 {
public static double VOS;
public static double vatRate = 0.1;
public static double expenseRate = 0.3;
public static double person1, person2, person3;
public static double[] dividend = new double[3];
public static void printReport(double person1, double person2, double person3) {
System.out.println("Value of supply : " + VOS);
System.out.println("VAT : " + getVAT());
System.out.println("Price : " + getPrice());
System.out.println("Income : " + getIncome());
System.out.println("Person1 : " + person1 +
"\nPerson2 : " + person2 +
"\nPerson3 : " + person3);
}
public static double getIncome() {
return VOS - getExpense();
}
public static double getExpense() {
return VOS * expenseRate;
}
public static double getPrice() {
return VOS + getVAT();
}
public static double getVAT() {
return VOS * vatRate;
}
public static double toPutGetIncome = getIncome(); // error hapeens here (Syntax error on token ";", { expected after this token)
// The "if conditional" starts from here
if( toPutGetIncome >= 10000 ) {
for (int n = 0; n < 3; n++) {
dividend[n] = Double.parseDouble(JOptionPane.showInputDialog("Enter a Dividend of Person" + (n+1)));
if(dividend[0] + dividend[1] + dividend[2] > 1) { System.out.println("Dividend over"); return; }
}
if(dividend[0] + dividend[1] + dividend[2] < 1) { System.out.println("Dividend short"); return; }
}
if( toPutGetIncome < 10000 ) { person1 = getIncome(); person2 = 0; person3 = 0; }
else{ person1 = getIncome()*dividend[0]; person2 = getIncome()*dividend[1]; person3 = getIncome()*dividend[2]; }
// ends
}
public class AccountingApp2 {
public static void main(String[] args) {
Accounting2.VOS = Double.parseDouble(JOptionPane.showInputDialog("Enter a VOS"));
if( Accounting2.VOS <= 0 ) { System.out.println("Wrong VOS"); return; }
Accounting2.printReport(Accounting2.person1, Accounting2.person2, Accounting2.person3);
}
} // the other error happens here (Syntax error, insert "}" to complete ClassBody)
我不确定它是否对你有帮助我正在研究外部 class 和内部 class。
所有代码都在 public class AccountngApp2 中。
我制作了另一个 class Accounting2 以从 AccountingApp2 移动方法,但在我移动方法时发生错误。
// The "if conditional" starts from here
if( toPutGetIncome >= 10000 ) {
for (int n = 0; n < 3; n++) {
dividend[n] = Double.parseDouble(JOptionPane.showInputDialog("Enter a Dividend of Person" + (n+1)));
if(dividend[0] + dividend[1] + dividend[2] > 1) { System.out.println("Dividend over"); return; }
}
if(dividend[0] + dividend[1] + dividend[2] < 1) { System.out.println("Dividend short"); return; }
}
if( toPutGetIncome < 10000 ) { person1 = getIncome(); person2 = 0; person3 = 0; }
else{ person1 = getIncome()*dividend[0]; person2 = getIncome()*dividend[1]; person3 = getIncome()*dividend[2]; }
// ends
这是无效的。 if
语句必须在方法、构造函数或静态初始值设定项中。
当我输入“if conditional”时会发生这种情况。 很抱歉带来了满满的代码,但是我整天都在尝试找出问题所在,但我仍在寻找问题。
import javax.swing.JOptionPane;
class Accounting2 {
public static double VOS;
public static double vatRate = 0.1;
public static double expenseRate = 0.3;
public static double person1, person2, person3;
public static double[] dividend = new double[3];
public static void printReport(double person1, double person2, double person3) {
System.out.println("Value of supply : " + VOS);
System.out.println("VAT : " + getVAT());
System.out.println("Price : " + getPrice());
System.out.println("Income : " + getIncome());
System.out.println("Person1 : " + person1 +
"\nPerson2 : " + person2 +
"\nPerson3 : " + person3);
}
public static double getIncome() {
return VOS - getExpense();
}
public static double getExpense() {
return VOS * expenseRate;
}
public static double getPrice() {
return VOS + getVAT();
}
public static double getVAT() {
return VOS * vatRate;
}
public static double toPutGetIncome = getIncome(); // error hapeens here (Syntax error on token ";", { expected after this token)
// The "if conditional" starts from here
if( toPutGetIncome >= 10000 ) {
for (int n = 0; n < 3; n++) {
dividend[n] = Double.parseDouble(JOptionPane.showInputDialog("Enter a Dividend of Person" + (n+1)));
if(dividend[0] + dividend[1] + dividend[2] > 1) { System.out.println("Dividend over"); return; }
}
if(dividend[0] + dividend[1] + dividend[2] < 1) { System.out.println("Dividend short"); return; }
}
if( toPutGetIncome < 10000 ) { person1 = getIncome(); person2 = 0; person3 = 0; }
else{ person1 = getIncome()*dividend[0]; person2 = getIncome()*dividend[1]; person3 = getIncome()*dividend[2]; }
// ends
}
public class AccountingApp2 {
public static void main(String[] args) {
Accounting2.VOS = Double.parseDouble(JOptionPane.showInputDialog("Enter a VOS"));
if( Accounting2.VOS <= 0 ) { System.out.println("Wrong VOS"); return; }
Accounting2.printReport(Accounting2.person1, Accounting2.person2, Accounting2.person3);
}
} // the other error happens here (Syntax error, insert "}" to complete ClassBody)
我不确定它是否对你有帮助我正在研究外部 class 和内部 class。 所有代码都在 public class AccountngApp2 中。 我制作了另一个 class Accounting2 以从 AccountingApp2 移动方法,但在我移动方法时发生错误。
// The "if conditional" starts from here
if( toPutGetIncome >= 10000 ) {
for (int n = 0; n < 3; n++) {
dividend[n] = Double.parseDouble(JOptionPane.showInputDialog("Enter a Dividend of Person" + (n+1)));
if(dividend[0] + dividend[1] + dividend[2] > 1) { System.out.println("Dividend over"); return; }
}
if(dividend[0] + dividend[1] + dividend[2] < 1) { System.out.println("Dividend short"); return; }
}
if( toPutGetIncome < 10000 ) { person1 = getIncome(); person2 = 0; person3 = 0; }
else{ person1 = getIncome()*dividend[0]; person2 = getIncome()*dividend[1]; person3 = getIncome()*dividend[2]; }
// ends
这是无效的。 if
语句必须在方法、构造函数或静态初始值设定项中。