Day3_9段階目

This commit is contained in:
m-shimizu
2026-09-24 15:57:49 +09:00
parent 5a8c7eb2fd
commit 99506c4369

View File

@@ -108,34 +108,62 @@ public class Main {
allData[10] = dept6; allData[10] = dept6;
//6段階目
//全データ表示 //全データ表示
for (int i = 0; i < allData.length; i++) { // for (int i = 0; i < allData.length; i++) {
System.out.println(allData[i]); // System.out.println(allData[i]);
} // }
//7段階目:instanceofで型を確認しよう //7段階目:instanceofで件数を数える
int employeeCount = 0; // int employeeCount = 0;
int departmentCount = 0; // int departmentCount = 0;
//
for(int i = 0; i < allData.length; i++) { // for(int i = 0; i < allData.length; i++) {
if(allData[i] instanceof EmployeeData) { // if(allData[i] instanceof EmployeeData) {
employeeCount++; // employeeCount++;
} // }
//
if(allData[i] instanceof DepartmentData) { // if(allData[i] instanceof DepartmentData) {
departmentCount++; // departmentCount++;
} // }
} // }
//
System.out.println("社員データ" + employeeCount + "件"); // System.out.println("社員データ" + employeeCount + "件");
System.out.println("部署データ" + departmentCount + "件"); // System.out.println("部署データ" + departmentCount + "件");
//8段階目
//全社員のメールアドレスを表示 //全社員のメールアドレスを表示
// for(int i = 0; i < allData.length; i++) {
// if(allData[i] instanceof EmployeeData) {
// EmployeeData employeeData = (EmployeeData) allData[i];
//
// System.out.println(employeeData.getMailAddress());
// }
// }
//部署名から社員を検索
String targetDepartmentId = null;
for(int i = 0; i < allData.length;i++) {
if(allData[i] instanceof DepartmentData) {
DepartmentData departmentData = (DepartmentData) allData[i];
if(departmentData.getNmDepartment().equals("システム開発事業部")) {
targetDepartmentId = departmentData.getIdDepartment();
}
}
}
for (int i = 0; i < allData.length; i++) { for (int i = 0; i < allData.length; i++) {
if(allData[i] instanceof EmployeeData) { if(allData[i] instanceof EmployeeData) {
EmployeeData employeeData = (EmployeeData) allData[i]; EmployeeData employeeData = (EmployeeData) allData[i];
System.out.println(employeeData.getMailAddress()); if(employeeData.getIdDepartment().equals(targetDepartmentId)) {
System.out.println(employeeData.getNmEmployee() + "\t" + employeeData.getMailAddress());
}
} }
} }