我试图将交互式输入添加到程序中。我已经工作了几个小时,无法解决。这是代码-
// 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);
最佳答案
Double.parseDouble (salaryString);
它的
Double.parseDouble
,而不是double.parseDouble
。 :)parseDouble
方法来自Double类。