私は従業員という名前のクラスを持っています。各従業員の表示を個別に書き出すのではなく、パラメーター変数を使用して for ループを使用して、各従業員 (3 人) の情報を表示しようとしています。
メソッド呼び出しの「employee1」部分に「setName」変数を使用したいと思います。これは可能ですか?
// 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());
}