From 99506c43697a3efd423d6bdc46c6050f52825a40 Mon Sep 17 00:00:00 2001 From: m-shimizu <26-m-e-stella-tecnica@it-college.jp> Date: Thu, 24 Sep 2026 15:57:49 +0900 Subject: [PATCH] =?UTF-8?q?Day3=5F9=E6=AE=B5=E9=9A=8E=E7=9B=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- em-oop/src/Main.java | 70 +++++++++++++++++++++++++++++++------------- 1 file changed, 49 insertions(+), 21 deletions(-) diff --git a/em-oop/src/Main.java b/em-oop/src/Main.java index 7622493..dff8f79 100644 --- a/em-oop/src/Main.java +++ b/em-oop/src/Main.java @@ -108,34 +108,62 @@ public class Main { allData[10] = dept6; + //6段階目 //全データ表示 - for (int i = 0; i < allData.length; i++) { - System.out.println(allData[i]); - } +// for (int i = 0; i < allData.length; i++) { +// System.out.println(allData[i]); +// } - //7段階目:instanceofで型を確認しよう - int employeeCount = 0; - int departmentCount = 0; - - for(int i = 0; i < allData.length; i++) { - if(allData[i] instanceof EmployeeData) { - employeeCount++; - } - - if(allData[i] instanceof DepartmentData) { - departmentCount++; - } - } - - System.out.println("社員データ" + employeeCount + "件"); - System.out.println("部署データ" + departmentCount + "件"); + //7段階目:instanceofで件数を数える +// int employeeCount = 0; +// int departmentCount = 0; +// +// for(int i = 0; i < allData.length; i++) { +// if(allData[i] instanceof EmployeeData) { +// employeeCount++; +// } +// +// if(allData[i] instanceof DepartmentData) { +// departmentCount++; +// } +// } +// +// System.out.println("社員データ" + employeeCount + "件"); +// System.out.println("部署データ" + departmentCount + "件"); + //8段階目 //全社員のメールアドレスを表示 - for(int i = 0; i < allData.length; i++) { +// 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++) { if(allData[i] instanceof EmployeeData) { EmployeeData employeeData = (EmployeeData) allData[i]; - System.out.println(employeeData.getMailAddress()); + if(employeeData.getIdDepartment().equals(targetDepartmentId)) { + + System.out.println(employeeData.getNmEmployee() + "\t" + employeeData.getMailAddress()); + } } }