尝试在Java的主类中创建对象时找不到符号
这是我的主要任务。这是一个通过周工资、基本工资+费率或小时工资+费率计算员工周工资的程序。所以我试图创建一个对象,然后遇到了这个障碍尝试在Java的主类中创建对象时找不到符号,java,Java,这是我的主要任务。这是一个通过周工资、基本工资+费率或小时工资+费率计算员工周工资的程序。所以我试图创建一个对象,然后遇到了这个障碍 public class Lab3A { /** * @param args the command line arguments */ public static void main(String[] args) { Employee emp1 = new Employee (bob); } }
public class Lab3A {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Employee emp1 = new Employee (bob);
}
}
这是我的类对象
public class Employee {
private static int empCount = 0;
private String empName;
private int empNumber;
private double empSalary;
private double empRate;
private double empHours;
private double empBase;
private int empPieces;
private int empType;
public Employee (String name){
name = this.empName;
empCount ++;
}
public void setEmployeePay (double salary){
salary= this.empSalary;
}
public void setEmployeePay (double rate, double hours){
rate = this.empRate;
hours = this.empHours;
}
public void setEmployeePay (double base, int pieces){
base = this.empBase;
pieces = this.empPieces;
}
public static int getCount (){
return empCount;
}
public String getName(){
return empName;
}
public int getNumber (int max, int min){
return ((int) (Math.random()*(max - min))) + min;
}
public double calculatePay(){
if (empCount == 1)
{
if (empHours > 0 && empRate > 0){
double pay = (empHours - 40) * 1.5;
return pay;
} else {
double pay = empRate * empHours;
return pay;
}
} else if (empSalary > 0){
double pay = empSalary / 52;
return pay;
} else {
double pay = empBase + empPieces * 24;
return pay;
}
}
}
如果有人能澄清我做错了什么,我将不胜感激。谢谢 你需要鲍勃,而不仅仅是鲍勃
bob被认为是字符串文字。bob单独被解释为变量标识符,您没有标记为bob的变量
也可以在创建对象之前创建名为bob的字符串变量:
String bob = "bob";
Employee employee = new Employee(bob);
但在这种情况下,最好将变量标记为name,因为它代表一个名称。哈哈,哇,我觉得自己太傻了,我早该知道的。谢谢你的帮助,巴德:我强烈建议结束这个问题,因为作者在提问之前显然没有尽力解决这个问题;在Employee类中添加到this.empName=name;你的缩进怎么了?缩进应该使代码更易于阅读