我正在嘗試將交互式輸入添加到程序中。我一直在研究它幾個小時,但無法弄清楚。下面是代碼 -雙變量的Java錯誤
// This program calculates an employee's take home pay.
public class Payrolls
import javax.swing.JOptionPane;
{
public static void main(String args[])
{
String salaryString;
double salary;
double stateTax;
double federalTax;
String numDependentsString;
double numDependents;
double dependentDeduction;
double totalWithholding;
double takeHomePay;
salaryString = JOptionPane.showInputDialog ("Enter Salary Here: ");
salary = double.parseDouble (salaryString);
numDependentsString = JOptionPane.showInputDialog ("Enter Number of Dependents: ");
numDependents = double.parseDouble (numDependentsString);
// Calculate state tax here.
stateTax = salary * .06;
System.out.println("State Tax: $" + stateTax);
// Calculate federal tax here.
federalTax = salary * .25;
System.out.println("Federal Tax: $" + federalTax);
// Calculate dependant deduction here.
dependentDeduction = (salary * .02) * numDependents;
System.out.println("Dependents: $" + dependentDeduction);
// Calculate total withholding here.
totalWithholding = stateTax + federalTax;
// Calculate take home pay here.
takeHomePay = salary - totalWithholding + dependentDeduction;
System.out.println("Salary: $" + salary);
System.out.println("Take Home Pay: $" + takeHomePay);
System.exit(0);
}
}
我有9個錯誤 -
Payrolls.java:19: error: class expected
salary = double.parseDouble (salaryString);
^
Payrolls.java:19: error: ';' expected
salary = double.parseDouble (salaryString);
^
Payrolls.java:19: error: not a statement
salary = double.parseDouble (salaryString);
^
Payrolls.java:19: error: ';' expected
salary = double.parseDouble (salaryString);
^
Payrolls.java:21: error: class expected
numDependents = double.parseDouble (numDependentsString);
^
Payrolls.java:21: error: ';' expected
numDependents = double.parseDouble (numDependentsString);
^
Payrolls.java:21: error: not a statement
numDependents = double.parseDouble (numDependentsString);
^
Payrolls.java:21: error: ';' expected
numDependents = double.parseDouble (numDependentsString);
「19」表示錯誤位於第19行。 –
如果您開始使用像eclipse這樣的編輯器會更好,這會讓您的生活變得輕鬆。 –
無論編譯錯誤是什麼,**在任何情況下**都不應該使用浮點變量來存儲貨幣數量。使用'BigDecimal'。 – EJP