我有一个名为 Employee 的类。我正在尝试使用带有参数变量的 for 循环来显示每个员工(有 3 个)的信息,而不必分别为每个员工写出显示。
我想将“setName”变量用于方法调用的“employee1”部分。这可能吗?
// Create the first employee using non-argument constructor
Employee employee1 = new Employee();
employee1.setName("Susan Meyers"); // Set the name
employee1.setDepartment("Accounting"); // Set department
employee1.setPosition("Vice President"); // Set position
employee1.setID(47899); // Set ID Number
// Create the second employee using all argument constructor
Employee employee2 = new Employee("Mark Jones", "IT", "Programmer", 39119);
// Create employee three using two-argument constructor
Employee employee3 = new Employee("Joy Rogers", 81774);
employee3.setDepartment("Manufacturing"); // Set department
employee3.setPosition("Engineer"); // Set position
// Display the data for employees 1, 2, 3 using for loop
for(int e = 1; e <= 3; e++) {
Integer.toString(e);
String setName = "employee" + "e";
System.out.println("Name: " + employee1.getName());
}