测试类中的错误:找不到符号

时间:2015-10-22 04:59:14

标签: java

我无法摆脱"找不到符号"它所说的错误" newEmployee.calcWTax(grossPay);"在测试课上。

我看了很多线程,我知道这与grossPay没有被宣布的事实有关,但我无法弄清楚在哪里。

此外,作为旁注,参数或方法中的注释中的任何内容都是因为我不确定我是否会使用它。

/*
Test class to test Employee.java 
*/

import javax.swing.JOptionPane;

public class EmployeeTest
{
public static void main(String[] args)
{
    //Scanner input = newScanner(System.in);
//gets ID number of employee
    Employee newEmployee = new Employee();
    String input = JOptionPane.showInputDialog("What is the ID number of the employee?");
    int id = Integer.parseInt(input);
    newEmployee.setID(id);  
//gets wage of employee
    input = JOptionPane.showInputDialog("What is the wage of this employee?");
    double wage = Double.parseDouble(input);
    newEmployee.setWage(wage);
//gets hours worked of employee
    input = JOptionPane.showInputDialog("How many hours did this employee work?");
    double hours = Double.parseDouble(input);
    newEmployee.setHours(hours);

//calculates and displays gross pay
newEmployee.calcGrossPay(hours, wage);
System.out.println(newEmployee.displayPay());

//calculates and displays withholding tax
newEmployee.calcWTax(grossPay);
System.out.println(newEmployee.displayTax());
    }

}

这是Employee.java:

public class Employee
{
    //private String name;
    private double wage;
    private int id;
    private double hours;
    private double grossPay;
    private double tax;
    private double netPay;


    public Employee(/*String aName*/)
    {
        //aName = name;
        wage = 0;
        id = 0;
        hours = 0;
        }
    public Employee(/*String aName,*/double aWage, int aID, double aHours)
    {
        //aName = name;
        aWage = wage;
        aID = id;
        aHours = hours;
        }

//mutators
    public void setID(int aID)
    {
        int newID = aID + id;
        id = newID;
    }
    /*public void setName(String aName)
    {
        String newName = aName;
        name = newName;
        }*/
    public void setWage(double aWage)
    {
        double newWage = aWage + wage;
        newWage = wage;
        }
    public void setHours(double aHours)
    {
        double newHours = aHours + hours;
        newHours = hours;
        }
    public void setGross(double aGross)
    {
        double newGross = aGross + grossPay;
        newGross = grossPay;
        }

//Accessors
    public int getID()
    {
        return id;
        }
    /*public String getName()
    {
        return name;
        }*/
    public double getWage()
    {
        return wage;
        }
    public double getHours()
    {
        return hours;
        }

//Computes gross pay
    public double calcGrossPay(double hours, double wage)
{
    if ( hours > 40 )
      {
      double extraHours = hours - 40;
      grossPay = ( 40 * wage ) + ( extraHours * (wage * 1.5) );
      }
    else grossPay = hours * wage;

    return grossPay;
}

//Displays gross pay
public double displayPay()
{
    return grossPay;
    }
//calculates Withholding tax
public double calcWTax(double gross)
{
    gross = grossPay;
    if (grossPay >= 0)
    {
        if (grossPay >= 0 && grossPay <= 300)
        {
            double wTax = grossPay * .1;
            wTax = tax;
            }
        else if (grossPay >= 300.01 && grossPay <= 400)
        {
            double wTax = grossPay * .12;
            wTax = tax;
            }
        else if (grossPay >=400.01 && grossPay <= 500)
        {
            double wTax = grossPay * .15;
            wTax = tax;
            }
        else if (grossPay >=500.01)
        {
            double wTax = grossPay * .2;
            wTax = tax;
            }
        else
        System.out.println("Error: Gross Pay is below 0");
        }
    else
    System.out.println("You haven't earned any money, get to work!");

    return tax;
    }

//displays withholding tax
public double displayTax()
{
    return tax;
    }
//calculates Net Pay
public double calcNetPay()
{
    double newNet = grossPay - tax;
    newNet = netPay;

    return netPay;
    }

//displays Net Pay
public double displayNet()
{
    return netPay;
    }


}

4 个答案:

答案 0 :(得分:0)

您的方法calcGrossPay()返回总薪水。您可以将它存储为几行,然后将其分配给变量I&#39; ll,方便地命名为grossPay。

struct typeable<T> {
    let value : String = "hello world"
}

protocol inside {
    typealias MyType
    func __myFunction() -> typeable<MyType>
}

protocol outside : inside {
    typealias MyType : inside
    func myFunction() -> typeable<MyType>
}

extension outside {
    final func __myFunction() -> typeable<MyType> {
        return self.myFunction()
    }
}

struct thing : outside {
    typealias MyType = thing
    func myFunction() -> typeable<thing> {
        return typeable<thing>()
    }
}

答案 1 :(得分:0)

您需要从calcGrossPay方法接收返回值,并将其传递给calcWTax方法。

在名为calcGrossPay的变量中声明grossPay的返回值并使用它。

double grossPay = newEmployee.calcGrossPay(hours, wage);
System.out.println(newEmployee.displayPay());

//calculates and displays withholding tax
newEmployee.calcWTax(grossPay);
  public double calcWTax(double gross)
  {
    gross = grossPay;

这应该是这个grossPay = gross。您可能希望将输入参数设置为类成员,而不是相反。

  public double calcWTax(double gross) {
  grossPay = gross

答案 2 :(得分:0)

您正在引用一个不存在的变量grossPay

答案 3 :(得分:0)

grossPayEmployee类的变量,而不是EmployeeTest类的变量。所以请使用newEmployee.calcGrossPay(hours,wage)代替grossPay