配列をArrayListに変更
This commit is contained in:
@@ -1,47 +1,49 @@
|
|||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Scanner;
|
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[];
|
||||||
BaseData[] allData = new BaseData[16];
|
// BaseData[] allData = new BaseData();
|
||||||
|
ArrayList<BaseData> allData = new ArrayList<>();
|
||||||
|
|
||||||
allData[0] = new EmployeeData("10000", "山田龍也", "ヤマダタツヤ", "yamada@hoge.jp", "aaa", "10");
|
allData.add(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[11] = new EmployeeData("10005", "丸井悠", "マルイハルカ", "haru@hoge.jp", "fff", "13");
|
||||||
allData[12] = new EmployeeData("10006", "涼元香織", "スズモトカオリ", "suzumoto@hoge.jp", "ggg", "13");
|
// allData[12] = new EmployeeData("10006", "涼元香織", "スズモトカオリ", "suzumoto@hoge.jp", "ggg", "13");
|
||||||
allData[13] = new EmployeeData("10007", "葉山稔", "ハヤマミノル", "mhayama@hoge.jp", "hhh", "14");
|
// allData[13] = new EmployeeData("10007", "葉山稔", "ハヤマミノル", "mhayama@hoge.jp", "hhh", "14");
|
||||||
allData[14] = new EmployeeData("10008", "川上朱里", "カワカミアカリ", "kawakami@hoge.jp", "iii", "14");
|
// allData[14] = new EmployeeData("10008", "川上朱里", "カワカミアカリ", "kawakami@hoge.jp", "iii", "14");
|
||||||
allData[15] = new EmployeeData("10009", "杉井肇", "スギイハジメ", "sugi@hoge.jp", "jjj", "15");
|
// allData[15] = new EmployeeData("10009", "杉井肇", "スギイハジメ", "sugi@hoge.jp", "jjj", "15");
|
||||||
|
//
|
||||||
DepartmentData dept = new DepartmentData();
|
// DepartmentData dept = new DepartmentData();
|
||||||
dept.setIdDepartment("10");
|
// dept.setIdDepartment("10");
|
||||||
dept.setNmDepartment("役員");
|
// dept.setNmDepartment("役員");
|
||||||
allData[5] = dept;
|
// allData[5] = dept;
|
||||||
dept = new DepartmentData();
|
// dept = new DepartmentData();
|
||||||
dept.setIdDepartment("11");
|
// dept.setIdDepartment("11");
|
||||||
dept.setNmDepartment("人事・総務部");
|
// dept.setNmDepartment("人事・総務部");
|
||||||
dept = new DepartmentData();
|
// dept = new DepartmentData();
|
||||||
allData[6] = dept;
|
// allData[6] = dept;
|
||||||
dept.setIdDepartment("12");
|
// dept.setIdDepartment("12");
|
||||||
dept.setNmDepartment("経理部");
|
// dept.setNmDepartment("経理部");
|
||||||
allData[7] = dept;
|
// allData[7] = dept;
|
||||||
dept = new DepartmentData();
|
// dept = new DepartmentData();
|
||||||
dept.setIdDepartment("13");
|
// dept.setIdDepartment("13");
|
||||||
dept.setNmDepartment("システム開発事業部");
|
// dept.setNmDepartment("システム開発事業部");
|
||||||
allData[8] = dept;
|
// allData[8] = dept;
|
||||||
dept = new DepartmentData();
|
// dept = new DepartmentData();
|
||||||
dept.setIdDepartment("14");
|
// dept.setIdDepartment("14");
|
||||||
dept.setNmDepartment("教育事業部");
|
// dept.setNmDepartment("教育事業部");
|
||||||
allData[9] = dept;
|
// allData[9] = dept;
|
||||||
dept = new DepartmentData();
|
// dept = new DepartmentData();
|
||||||
dept.setIdDepartment("15");
|
// dept.setIdDepartment("15");
|
||||||
dept.setNmDepartment("営業企画部");
|
// dept.setNmDepartment("営業企画部");
|
||||||
allData[10] = dept;
|
// allData[10] = dept;
|
||||||
|
|
||||||
Scanner scanner = new Scanner(System.in);
|
Scanner scanner = new Scanner(System.in);
|
||||||
|
|
||||||
@@ -59,26 +61,30 @@ public class Main {
|
|||||||
System.out.println("1:全検索 2:条件検索 それ以外:戻る");
|
System.out.println("1:全検索 2:条件検索 それ以外:戻る");
|
||||||
usertype = scanner.nextLine();
|
usertype = scanner.nextLine();
|
||||||
if (usertype.equals("1")) {
|
if (usertype.equals("1")) {
|
||||||
for (int i = 0; i < allData.length; i++)
|
for (int i = 0; i < allData.size(); i++)
|
||||||
if (allData[i] instanceof EmployeeData) {
|
if (allData.get(i) instanceof EmployeeData) {
|
||||||
System.out.println(allData[i].toString());
|
System.out.println(allData.get(i).toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (usertype.equals("2")) {
|
} else if (usertype.equals("2")) {
|
||||||
System.out.println("IDを入力してください");
|
System.out.println("IDを入力してください");
|
||||||
usertype = scanner.nextLine();
|
usertype = scanner.nextLine();
|
||||||
|
|
||||||
for (int i = 0; i < allData.length; i++)
|
boolean result = false;
|
||||||
if (allData[i] instanceof EmployeeData) {
|
for (int i = 0; i < allData.size(); i++)
|
||||||
EmployeeData employee = (EmployeeData) allData[i];
|
if (allData.get(i) instanceof EmployeeData) {
|
||||||
|
EmployeeData employee = (EmployeeData) allData.get(i);
|
||||||
if (employee.getIdEmployee().equals(usertype)) {
|
if (employee.getIdEmployee().equals(usertype)) {
|
||||||
|
result = true;
|
||||||
System.out.println(employee.toString());
|
System.out.println(employee.toString());
|
||||||
break;
|
break;
|
||||||
} else {
|
|
||||||
System.out.println("入力された値で情報がみつかりませんでした");
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
if (result == false) {
|
||||||
|
System.out.println("入力された値で情報がみつかりませんでした");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
continue;
|
continue;
|
||||||
@@ -87,105 +93,110 @@ public class Main {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//2:登録
|
||||||
|
if (usertype.equals("2")) {
|
||||||
|
System.out.println("社員IDを入力してください");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//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];
|
|
||||||
// System.out.println(emp.getMailAddress());
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// int emp=0;
|
|
||||||
// int dep=0;
|
|
||||||
// for(int i=0;i<allData.length;i++) {
|
|
||||||
// if(allData[i] instanceof EmployeeData) {
|
|
||||||
// emp++;
|
|
||||||
// }
|
|
||||||
// if(allData[i] instanceof DepartmentData) {
|
|
||||||
// dep++;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// System.out.println("社員データ:"+emp+"件");
|
|
||||||
// System.out.println("部署データ:"+dep+"件");
|
|
||||||
|
|
||||||
// employees[0] = new EmployeeData("10000", "山田龍也", "ヤマダタツヤ", "yamada@hoge.jp", "aaa", "10");
|
|
||||||
// employees[1] = new EmployeeData("10001","高橋準","タカハシジュン","jtaka@hoge.jp","bbb","10");
|
|
||||||
// employees[2] = new EmployeeData("10002","麻枝史明","マエダフミアキ","fmak@hoge.jp","ccc","11");
|
|
||||||
// employees[3] = new EmployeeData("10003","丸戸章介","マルトショウスケ","marusyo@hoge.jp","ddd","12");
|
|
||||||
// employees[4] = new EmployeeData("10004","三宅武","ミヤケタケシ","miya@hoge.jp","eee","13");
|
|
||||||
|
|
||||||
// System.out.println(employees[0].toCSV());
|
|
||||||
// System.out.println(employees[0].getPrimaryKeyValue());
|
|
||||||
|
|
||||||
// Scanner sc = new Scanner(System.in);
|
|
||||||
// //
|
|
||||||
// for (int i = 0; i < employees.length; i++) {
|
|
||||||
// System.out.println("1:検索 2:登録 3:更新 4:削除 0:終了");
|
|
||||||
// String id = sc.nextLine();
|
|
||||||
// boolean result = false;
|
|
||||||
//
|
|
||||||
// if (id.equals("0")) {
|
|
||||||
// System.out.println("システムを終了します");
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// if (employees[i].getPrimaryKeyValue().equals(id)) {
|
|
||||||
// result = true;
|
|
||||||
// employees[i].toString();
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// if (result == false) {
|
|
||||||
// System.out.println("該当する社員が見つかりませんでした");
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// for (int i = 0; i < 5; i++) {
|
|
||||||
// if (employee[i].getNmEmployee() == null) {
|
|
||||||
// continue;
|
|
||||||
// }
|
|
||||||
// System.out.println(employee[i]);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// System.out.println("現在の社員データ数"+EmployeeData.getEmpCount());
|
|
||||||
//
|
|
||||||
// System.out.println(EmployeeData.COMPANY_NAME);
|
|
||||||
|
|
||||||
// System.out.println();
|
|
||||||
// System.out.println(employee.nmEmployee);
|
|
||||||
// System.out.println(employee.knEmployee);
|
|
||||||
// System.out.println(employee.mailAddress);
|
|
||||||
// System.out.println(employee.password);
|
|
||||||
// System.out.println(employee.idDepartment);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//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];
|
||||||
|
// System.out.println(emp.getMailAddress());
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// int emp=0;
|
||||||
|
// int dep=0;
|
||||||
|
// for(int i=0;i<allData.length;i++) {
|
||||||
|
// if(allData[i] instanceof EmployeeData) {
|
||||||
|
// emp++;
|
||||||
|
// }
|
||||||
|
// if(allData[i] instanceof DepartmentData) {
|
||||||
|
// dep++;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// System.out.println("社員データ:"+emp+"件");
|
||||||
|
// System.out.println("部署データ:"+dep+"件");
|
||||||
|
|
||||||
|
// employees[0] = new EmployeeData("10000", "山田龍也", "ヤマダタツヤ", "yamada@hoge.jp", "aaa", "10");
|
||||||
|
// employees[1] = new EmployeeData("10001","高橋準","タカハシジュン","jtaka@hoge.jp","bbb","10");
|
||||||
|
// employees[2] = new EmployeeData("10002","麻枝史明","マエダフミアキ","fmak@hoge.jp","ccc","11");
|
||||||
|
// employees[3] = new EmployeeData("10003","丸戸章介","マルトショウスケ","marusyo@hoge.jp","ddd","12");
|
||||||
|
// employees[4] = new EmployeeData("10004","三宅武","ミヤケタケシ","miya@hoge.jp","eee","13");
|
||||||
|
|
||||||
|
// System.out.println(employees[0].toCSV());
|
||||||
|
// System.out.println(employees[0].getPrimaryKeyValue());
|
||||||
|
|
||||||
|
// Scanner sc = new Scanner(System.in);
|
||||||
|
// //
|
||||||
|
// for (int i = 0; i < employees.length; i++) {
|
||||||
|
// System.out.println("1:検索 2:登録 3:更新 4:削除 0:終了");
|
||||||
|
// String id = sc.nextLine();
|
||||||
|
// boolean result = false;
|
||||||
|
//
|
||||||
|
// if (id.equals("0")) {
|
||||||
|
// System.out.println("システムを終了します");
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
// if (employees[i].getPrimaryKeyValue().equals(id)) {
|
||||||
|
// result = true;
|
||||||
|
// employees[i].toString();
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// if (result == false) {
|
||||||
|
// System.out.println("該当する社員が見つかりませんでした");
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// for (int i = 0; i < 5; i++) {
|
||||||
|
// if (employee[i].getNmEmployee() == null) {
|
||||||
|
// continue;
|
||||||
|
// }
|
||||||
|
// System.out.println(employee[i]);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// System.out.println("現在の社員データ数"+EmployeeData.getEmpCount());
|
||||||
|
//
|
||||||
|
// System.out.println(EmployeeData.COMPANY_NAME);
|
||||||
|
|
||||||
|
// System.out.println();
|
||||||
|
// System.out.println(employee.nmEmployee);
|
||||||
|
// System.out.println(employee.knEmployee);
|
||||||
|
// System.out.println(employee.mailAddress);
|
||||||
|
// System.out.println(employee.password);
|
||||||
|
// System.out.println(employee.idDepartment);
|
||||||
|
|||||||
Reference in New Issue
Block a user