検索機能を追加

This commit is contained in:
2026-09-24 14:15:39 +09:00
parent 127a193893
commit af0016324b

View File

@@ -1,14 +1,22 @@
import java.util.Scanner;
public class Main { public class Main {
public static void main(String[] args) { public static void main(String[] args) {
BaseData employee = new EmployeeData();
// BaseData employee = new EmployeeData();
BaseData[] employees = new BaseData[5]; BaseData[] employees = new BaseData[5];
BaseData[] allData = new BaseData[11]; BaseData[] allData = new BaseData[16];
allData[0] = new EmployeeData("10000", "山田龍也", "ヤマダタツヤ", "yamada@hoge.jp", "aaa", "10"); allData[0] = new EmployeeData("10000", "山田龍也", "ヤマダタツヤ", "yamada@hoge.jp", "aaa", "10");
allData[1] = new EmployeeData("10001", "高橋準", "タカハシジュン", "jtaka@hoge.jp", "bbb", "10"); allData[1] = new EmployeeData("10001", "高橋準", "タカハシジュン", "jtaka@hoge.jp", "bbb", "10");
allData[2] = new EmployeeData("10002", "麻枝史明", "マエダフミアキ", "fmak@hoge.jp", "ccc", "11"); allData[2] = new EmployeeData("10002", "麻枝史明", "マエダフミアキ", "fmak@hoge.jp", "ccc", "11");
allData[3] = new EmployeeData("10003", "丸戸章介", "マルトショウスケ", "marusyo@hoge.jp", "ddd", "12"); allData[3] = new EmployeeData("10003", "丸戸章介", "マルトショウスケ", "marusyo@hoge.jp", "ddd", "12");
allData[4] = new EmployeeData("10004", "三宅武", "ミヤケタケシ", "miya@hoge.jp", "eee", "13"); allData[4] = new EmployeeData("10004", "三宅武", "ミヤケタケシ", "miya@hoge.jp", "eee", "13");
allData[11] = new EmployeeData("10005", "丸井悠", "マルイハルカ", "haru@hoge.jp", "fff", "13");
allData[12] = new EmployeeData("10006", "涼元香織", "スズモトカオリ", "suzumoto@hoge.jp", "ggg", "13");
allData[13] = new EmployeeData("10007", "葉山稔", "ハヤマミノル", "mhayama@hoge.jp", "hhh", "14");
allData[14] = new EmployeeData("10008", "川上朱里", "カワカミアカリ", "kawakami@hoge.jp", "iii", "14");
allData[15] = new EmployeeData("10009", "杉井肇", "スギイハジメ", "sugi@hoge.jp", "jjj", "15");
DepartmentData dept = new DepartmentData(); DepartmentData dept = new DepartmentData();
dept.setIdDepartment("10"); dept.setIdDepartment("10");
@@ -35,32 +43,78 @@ public class Main {
dept.setNmDepartment("営業企画部"); dept.setNmDepartment("営業企画部");
allData[10] = dept; allData[10] = dept;
DepartmentData dep = null; Scanner scanner = new Scanner(System.in);
EmployeeData emp ;
String nmD=null;
for (int i=0; i < allData.length; i++) { while (true) {
if (allData[i] instanceof DepartmentData) { System.out.println("1:検索 2:登録 3:更新 4:削除 0:終了");
dep = (DepartmentData) allData[i]; String usertype = scanner.nextLine();
if (dep.getNmDepartment().equals("システム開発事業部")) {
nmD=dep.getIdDepartment(); //0:終了
} if (usertype.equals("0")) {
break;
} }
//1:検索
if (usertype.equals("1")) {
System.out.println("1:全検索 2:条件検索 それ以外:戻る");
usertype = scanner.nextLine();
if (usertype.equals("1")) {
for (int i = 0; i < allData.length; i++)
if (allData[i] instanceof EmployeeData) {
System.out.println(allData[i].toString());
}
} else if (usertype.equals("2")) {
System.out.println("IDを入力してください");
usertype = scanner.nextLine();
for (int i = 0; i < allData.length; i++)
if (allData[i] instanceof EmployeeData) {
EmployeeData employee = (EmployeeData) allData[i];
if (employee.getIdEmployee().equals(usertype)) {
System.out.println(employee.toString());
break;
} else {
System.out.println("入力された値で情報がみつかりませんでした");
break;
}
}
} else {
continue;
}
} }
for (int i = 0; i < allData.length; i++) {
if (allData[i] instanceof EmployeeData) {
emp = (EmployeeData) allData[i];
if (emp.getIdDepartment().equals(nmD)) {
System.out.println(emp.getNmEmployee() + "\t" + emp.getMailAddress());
}
} }
//Day3.9---所属部署から従業員のメアドを検索する
// DepartmentData dep = null;
// EmployeeData emp;
// String nmD = null;
//
// for (int i = 0; i < allData.length; i++) {
// if (allData[i] instanceof DepartmentData) {
// dep = (DepartmentData) allData[i];
// if (dep.getNmDepartment().equals("システム開発事業部")) {
// nmD = dep.getIdDepartment();
// }
// }
//
// }
//
// for (int i = 0; i < allData.length; i++) {
// if (allData[i] instanceof EmployeeData) {
// emp = (EmployeeData) allData[i];
// if (emp.getIdDepartment().equals(nmD)) {
// System.out.println(emp.getNmEmployee() + "\t" + emp.getMailAddress());
// }
//
// }
//
// }
// 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 emp = (EmployeeData) allData[i]; // EmployeeData emp = (EmployeeData) allData[i];
@@ -91,9 +145,9 @@ public class Main {
// System.out.println(employees[0].getPrimaryKeyValue()); // System.out.println(employees[0].getPrimaryKeyValue());
// Scanner sc = new Scanner(System.in); // Scanner sc = new Scanner(System.in);
// // //
// for (int i = 0; i < employees.length; i++) { // for (int i = 0; i < employees.length; i++) {
// System.out.println("検索したい社員IDを入力してください(終了する場合は0)"); // System.out.println("1:検索 2:登録 3:更新 4:削除 0:終了");
// String id = sc.nextLine(); // String id = sc.nextLine();
// boolean result = false; // boolean result = false;
// //
@@ -112,10 +166,9 @@ public class Main {
// } // }
// //
// } // }
// } //
// for (int i = 0; i < 5; i++) {
// for(int i=0;i<5;i++) { // if (employee[i].getNmEmployee() == null) {
// if(employee[i].getNmEmployee()==null) {
// continue; // continue;
// } // }
// System.out.println(employee[i]); // System.out.println(employee[i]);
@@ -135,5 +188,4 @@ public class Main {
// System.out.println(employee.idDepartment); // System.out.println(employee.idDepartment);
} }
}
} }