検索機能を追加

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 static void main(String[] args) {
BaseData employee = new EmployeeData();
// BaseData employee = new EmployeeData();
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[1] = new EmployeeData("10001", "高橋準", "タカハシジュン", "jtaka@hoge.jp", "bbb", "10");
allData[2] = new EmployeeData("10002", "麻枝史明", "マエダフミアキ", "fmak@hoge.jp", "ccc", "11");
allData[3] = new EmployeeData("10003", "丸戸章介", "マルトショウスケ", "marusyo@hoge.jp", "ddd", "12");
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();
dept.setIdDepartment("10");
@@ -35,32 +43,78 @@ public class Main {
dept.setNmDepartment("営業企画部");
allData[10] = dept;
DepartmentData dep = null;
EmployeeData emp ;
String nmD=null;
Scanner scanner = new Scanner(System.in);
for (int i=0; i < allData.length; i++) {
if (allData[i] instanceof DepartmentData) {
dep = (DepartmentData) allData[i];
if (dep.getNmDepartment().equals("システム開発事業部")) {
nmD=dep.getIdDepartment();
}
while (true) {
System.out.println("1:検索 2:登録 3:更新 4:削除 0:終了");
String usertype = scanner.nextLine();
//0:終了
if (usertype.equals("0")) {
break;
}
}
for (int i = 0; i < allData.length; i++) {
//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) {
emp = (EmployeeData) allData[i];
if (emp.getIdDepartment().equals(nmD)) {
System.out.println(emp.getNmEmployee() + "\t" + emp.getMailAddress());
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;
}
}
}
//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++) {
// if (allData[i] instanceof EmployeeData) {
// EmployeeData emp = (EmployeeData) allData[i];
@@ -91,9 +145,9 @@ public class Main {
// System.out.println(employees[0].getPrimaryKeyValue());
// Scanner sc = new Scanner(System.in);
//
// //
// 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();
// boolean result = false;
//
@@ -112,8 +166,7 @@ public class Main {
// }
//
// }
// }
//
// for (int i = 0; i < 5; i++) {
// if (employee[i].getNmEmployee() == null) {
// continue;
@@ -136,4 +189,3 @@ public class Main {
}
}
}