【发布时间】:2020-04-30 20:52:52
【问题描述】:
我必须编写一个 Employee Class,然后在 Main 中调用它来运行测试项目。
我在方法 empRate 上不断收到“无法解析符号”。它存在于 Employee20 类中,但是当我从 EmployeeMain20 调用该类和方法时,出现“无法解析符号”错误。
网络搜索给了我各种关于 IntelliJ 错误、更改文件路径和传输项目的信息,所有这些都让我感到困惑。 IntelliJ 仅安装在这台计算机上,没有从其他来源传输或访问任何文件,创建一个干净的副本并没有解决问题。
这是有问题的代码。每行中的第二个“empRate”是我得到“无法解析符号”的地方。
Employee20 empRate = new empRate("John", "Smith", 10000, 10, 10);
Employee20 empRate1 = new empRate("Sue", "Smith", 20000, 10, 10);
这是调用类EmployeeMain20的完整代码:
public class EmployeeMain20 {
//Year added to differentiate from [other] assignments
public static void main(String[] args){
Employee20 empRate = new empRate("John", "Smith", 10000, 10, 10);
Employee20 empRate1 = new empRate("Sue", "Smith", 20000, 10, 10);
double wage = empRate.getWage();
System.out.println("Employee name: " + empRate1.firstName + empRate1.lastName);
System.out.println("Employee wage: " + "$" + wage);
//emp.greet();
System.out.println("===============================================");
wage = empRate1.getWage(); //wage defined in Employee2020 class
System.out.println("Employee name: " + empRate1.firstName + empRate1.lastName);
System.out.println("Employee wage: " + "$" + wage);
//emp.greet();
}
}
这是被调用的类Employee20的代码:
public class Employee20 {
//Year added to differentiate from [other] assignments
String firstName, lastName;
int baseSalary, overtime, rate;
public double getWage(){
double wage = baseSalary * (overtime * rate);
return wage;
}
public void empRate(String fname, String lname, int base, int overTime, int unitrate){
firstName = fname;
lastName = lname;
baseSalary = base;
overtime = overTime;
rate = unitrate;
}
}
我在另一项任务中遇到了类似的问题。我想如果我能找出如何解决一个,我可以解决两个。
【问题讨论】:
标签: java class methods calling-convention cannot-find-symbol