Closed. This question is not reproducible or was caused by typos。它当前不接受答案。












想改善这个问题吗?更新问题,以便将其作为on-topic用于堆栈溢出。

12个月前关闭。



Improve this question




编译此代码时,出现错误,指出(String [] args)之后应使用分号。我不能把头缠住它。如果我加一,那么我会得到十多个错误

导入java.util .;
导入java.text .;

公共(public)类PayCheck
{
private String givenName;
private double totalWage;
private double totalHours;

private double gross, netPay, tax, ssnTax;

static String employer="PrismHR";
static double taxRate = 0.22;
static double ssRate = 0.06;

public static void main (String[] args) PayCheck()
{
    Scanner std = new Scanner(System.in);

    System.out.println("Enter employee name: ");
    givenName = std.nextLine();

    System.out.println("Enter pay rate and hours worked: ");
    totalWage = std.nextDouble();
    totalHours = std.nextDouble();
    gross = totalWage*totalHours;
    tax = gross*taxRate;
    ssnTax = gross*ssRate;
    netPay = gross-tax-ssnTax;
}

public PayCheck(String name, double wage, double hours)
{
    this.givenName = name;
    this.totalHours = hours;
    this.totalWage = wage;

    gross = totalWage * totalHours;
    tax = gross * taxRate;
    ssnTax = gross * ssRate;
    netPay = gross - tax - ssnTax;
}

public String toString()
{
    String emptyString = "";

    NumberFormat formats = new DecimalFormat(".##");

    emptyString += "Employer: " + employer + "\n";
    emptyString += "Employee: " + givenName +"\n";
    emptyString += "Gross income: $" + formats.format(gross)+"\n";
    emptyString += "Federal Tax: $" + formats.format(tax) + "\n";
    emptyString += "Social Security Tax: $" + formats.format(ssnTax) +"\n";
    emptyString += "Net Pay:  " + formats.format(netPay);

    return emptyString;
}

}

最佳答案

通常,这适用于所有编程语言,错误本身可能并不准确。就您而言,那里的函数调用有点……。

public static void main (String[] args) PayCheck()
{
    ...
}

摆脱PayCheck()。我不确定您要如何处理它,但这绝对是导致错误的原因。

07-24 21:48