0

我需要为我的作业做这个,但是,当我编译它说我在打印数据中的变量无法解析为类型时,我做错了什么?我还需要为此创建一个测试器类。

public class PayCalculator


{
  private double hourlyRate;
  private double hoursWorked;

  /**
   * Two parameter constructor
   * Add hourlyRate and hoursWorked
   * @param the hourly rate
   * @param the hours worked
   */
  public PayCalculator(double aHourlyRate, double aHoursWorked)
  {
    hourlyRate = aHourlyRate;
    hoursWorked = aHoursWorked;
  }

  /**
   * sets the hourly rate
   * @return hourlyRate
   */ 
  public void setHourlyRate(double aHourlyRate)
  {
    hourlyRate = aHourlyRate;
  }

  /**
   * gets the hourly rate
   * @param hourlyRate
   */
  public double getHourlyRate()
  {
    return hourlyRate;
  }

  /**
   * sets the hours worked
   * @return hoursWorked
   */ 
  public void setHoursWorked(double aHoursWorked)
  {
    hoursWorked = aHoursWorked;
  }

  /**
   * gets the hours worked
   * @param hours worked
   */
  public double getHoursWorked()
  {
    return hoursWorked;
  }



  public boolean workedOvertime()
  {
    if (hoursWorked > 40)
    {
      return true;
    }
    else 
    {
      return false;
    }
  }

  public double numHoursOvertime()
  {
    if (hoursWorked > 40)
    {
      return hoursWorked - 40;
    }
    else 
    {
      return 0;
    }
  }

  public double calculateGrossPay()
  {
    if (hourlyRate  <= 10.25)
    {
      if (hourlyRate <= 40)
        return hourlyRate * hoursWorked;
    }
    else 
    {  
      double grossPay = ((40 * hourlyRate) + ((hourlyRate * 2) * hoursWorked - 40));
      return grossPay;
    }

    if (hoursWorked <= 60)
    {
      return hourlyRate * hoursWorked;
    }
    else
    {
      return 60 * hourlyRate;
    }
  }

  public double determineTaxRate(double grossPay)
  {
    if (grossPay >= 800)
    {
      double tax = 0;
      tax = grossPay * 0.37;
      return tax;
    }
    else if ( grossPay >= 400)
    {
      double tax = 0;
      tax = grossPay * 0.22;
      return tax;
    }
    else
    {
      double tax = 0;
      tax = grossPay * 0.12;
      return tax;
    }
  }

  public double calculateNetPay(double grossPay, double tax)
  {
    double calculateNetPay = grossPay - tax;
    return calculateNetPay;
  }

  public void printData()
  {
    System.out.println("Hours Worked: " + hoursWorked);
    System.out.println("Hourly rate: " + hourlyRate);
    System.out.println("Number of hours of overtime worked: " + numHoursOvertime);
    System.out.println("Worked overtime? " + workedOvertime);
    System.out.println("Gross pay: " + calculateGrossPay);
    System.out.println("Tax Rate: " + determineTaxRate);
    System.out.println("Net Pay: " + calculateNetPay);
  }


}
4

5 回答 5

1

你不能methods只用他们的名字称呼正义。像下面这样称呼他们。

numHoursOvertime()
workedOvertime()
determineTaxRate(10) // example
calculateNetPay(10, 10) // example

您可以在此处了解有关方法的更多信息。

于 2013-03-08T01:56:55.187 回答
0

这些方法不能在System.out.println();调用中使用。相反,在方法中,使用方法创建新int的并分配它们,然后将它们打印出来。例如:

int a = calculateTax();
System.out.println("tax: " + a);
于 2013-03-08T01:56:44.050 回答
0

numHoursOvertime workingOvertime 是方法。你不能就这样称呼他们!

numHoursOvertime()
workedOvertime()
于 2013-03-08T01:56:59.387 回答
0

您令人困惑的方法名称和变量名称。例如,使用

numHoursOvertime()

并不是

numHoursOvertime
于 2013-03-08T01:59:01.593 回答
0

用括号调用方法hoursWorked()。我在代码中看到的另一个可能的错误是未定义public double determineTaxRate(double grossPay)变量的方法tax

于 2013-03-08T01:59:20.923 回答