Day3_6段階目
This commit is contained in:
59
em-oop/src/DepartmentData.java
Normal file
59
em-oop/src/DepartmentData.java
Normal file
@@ -0,0 +1,59 @@
|
||||
|
||||
public class DepartmentData extends BaseData{
|
||||
|
||||
private String idDepartment;
|
||||
private String nmDepartment;
|
||||
|
||||
//gettre・setter
|
||||
//部署IDのgetter
|
||||
public String getIdDepartment() {
|
||||
return idDepartment;
|
||||
}
|
||||
|
||||
//部署IDのsetter
|
||||
public void setIdDepartment(String idDepartment) {
|
||||
this.idDepartment = idDepartment;
|
||||
}
|
||||
|
||||
//部署名のgetter
|
||||
public String getNmDepartment() {
|
||||
return nmDepartment;
|
||||
}
|
||||
|
||||
//部署名のsetter
|
||||
public void setNmDepartment(String nmDepartment) {
|
||||
this.nmDepartment = nmDepartment;
|
||||
}
|
||||
|
||||
//部署名を文字列として返す
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.getIdDepartment() + "\t" + this.getNmDepartment();
|
||||
}
|
||||
|
||||
//CSV形式で返す
|
||||
@Override
|
||||
public String toCSV() {
|
||||
return this.getIdDepartment() + "," + this.getNmDepartment();
|
||||
|
||||
}
|
||||
|
||||
//部署IDを返す
|
||||
@Override
|
||||
public String getPrimaryKeyValue() {
|
||||
return this.getIdDepartment();
|
||||
|
||||
}
|
||||
|
||||
//部署名
|
||||
// @Override
|
||||
// public String toCSV() {
|
||||
// return this.getIdDepartment() + "," + getNmDepartment();
|
||||
// }
|
||||
|
||||
//部署ID
|
||||
// @Override
|
||||
// public String getPrimaryKeyValue() {
|
||||
// return this.getIdDepartment();
|
||||
// }
|
||||
}
|
||||
@@ -8,6 +8,7 @@ public class EmployeeData extends BaseData {
|
||||
private String password;
|
||||
private String idDepartment;
|
||||
|
||||
//社員データ件数
|
||||
private static int empCount = 0;
|
||||
|
||||
//引数なしコンストラクタ
|
||||
@@ -35,9 +36,9 @@ public class EmployeeData extends BaseData {
|
||||
|
||||
}
|
||||
|
||||
public static int getEmpCount() {
|
||||
return empCount;
|
||||
}
|
||||
// public static int getEmpCount() {
|
||||
// return empCount;
|
||||
// }
|
||||
|
||||
public String getIdEmployee() {
|
||||
return idEmployee;
|
||||
@@ -54,7 +55,8 @@ public class EmployeeData extends BaseData {
|
||||
|
||||
this.idEmployee = idEmployee;
|
||||
}
|
||||
|
||||
|
||||
//社員名
|
||||
public String getNmEmployee() {
|
||||
return nmEmployee;
|
||||
}
|
||||
@@ -71,6 +73,7 @@ public class EmployeeData extends BaseData {
|
||||
this.nmEmployee = nmEmployee;
|
||||
}
|
||||
|
||||
//社員名カナ
|
||||
public String getKnEmployee() {
|
||||
return knEmployee;
|
||||
}
|
||||
@@ -79,6 +82,7 @@ public class EmployeeData extends BaseData {
|
||||
this.knEmployee = knEmployee;
|
||||
}
|
||||
|
||||
//メールアドレス
|
||||
public String getMailAddress() {
|
||||
return mailAddress;
|
||||
}
|
||||
@@ -87,6 +91,7 @@ public class EmployeeData extends BaseData {
|
||||
this.mailAddress = mailAddress;
|
||||
}
|
||||
|
||||
//パスワード
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
@@ -95,6 +100,7 @@ public class EmployeeData extends BaseData {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
//部署ID
|
||||
public String getIdDepartment() {
|
||||
return idDepartment;
|
||||
}
|
||||
@@ -102,11 +108,18 @@ public class EmployeeData extends BaseData {
|
||||
public void setIdDepartment(String idDepartment) {
|
||||
this.idDepartment = idDepartment;
|
||||
}
|
||||
|
||||
public boolean isMatchID(String id) {
|
||||
return this.idEmployee.equals(id);
|
||||
|
||||
//社員データ件数を取得
|
||||
public static int getEmpCount() {
|
||||
return empCount;
|
||||
}
|
||||
|
||||
//社員IDが一致するか確認
|
||||
public boolean isMatchID(String id) {
|
||||
return this.idEmployee != null && this.idEmployee.equals(id);
|
||||
}
|
||||
|
||||
//社員情報を文字列として返す
|
||||
@Override
|
||||
public String toString() {
|
||||
|
||||
@@ -119,6 +132,7 @@ public class EmployeeData extends BaseData {
|
||||
|
||||
}
|
||||
|
||||
//CSV形式で返す
|
||||
@Override
|
||||
public String toCSV() {
|
||||
|
||||
@@ -130,6 +144,7 @@ public class EmployeeData extends BaseData {
|
||||
+ this.getIdDepartment();
|
||||
}
|
||||
|
||||
//社員IDを返す
|
||||
@Override
|
||||
public String getPrimaryKeyValue() {
|
||||
return this.getIdEmployee();
|
||||
|
||||
@@ -1,18 +1,16 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class Main {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
//Day3_5段階目:BaseData型で社員を作成
|
||||
BaseData employee = new EmployeeData(
|
||||
"10000",
|
||||
"山田龍也",
|
||||
"ヤマダタツヤ",
|
||||
"yamada@hoge.jp",
|
||||
"aaa",
|
||||
"10"
|
||||
);
|
||||
// BaseData employee = new EmployeeData(
|
||||
// "10000",
|
||||
// "山田龍也",
|
||||
// "ヤマダタツヤ",
|
||||
// "yamada@hoge.jp",
|
||||
// "aaa",
|
||||
// "10"
|
||||
// );
|
||||
|
||||
// System.out.println(employee.toCSV());
|
||||
// System.out.println(employee.getPrimaryKeyValue());
|
||||
@@ -20,7 +18,14 @@ public class Main {
|
||||
//Day3_5段階目:BaseData型の配列を作成
|
||||
BaseData[] Employees = new EmployeeData[5];
|
||||
|
||||
Employees[0] = employee;
|
||||
Employees[0] = new EmployeeData(
|
||||
"10000",
|
||||
"山田龍也",
|
||||
"ヤマダタツヤ",
|
||||
"yamada@hoge.jp",
|
||||
"aaa",
|
||||
"10"
|
||||
);
|
||||
|
||||
Employees[1] = new EmployeeData(
|
||||
"10001",
|
||||
@@ -58,6 +63,54 @@ public class Main {
|
||||
"13"
|
||||
);
|
||||
|
||||
//
|
||||
BaseData[] allData = new BaseData[11];
|
||||
|
||||
//
|
||||
for (int i = 0; i < Employees.length; i++) {
|
||||
allData[i] = Employees[i];
|
||||
}
|
||||
|
||||
DepartmentData dept1 = new DepartmentData();
|
||||
dept1.setIdDepartment("10");
|
||||
dept1.setNmDepartment("役員");
|
||||
|
||||
allData[5] = dept1;
|
||||
|
||||
DepartmentData dept2 = new DepartmentData();
|
||||
dept2.setIdDepartment("11");
|
||||
dept2.setNmDepartment("人事・総務部");
|
||||
|
||||
allData[6] = dept2;
|
||||
|
||||
DepartmentData dept3 = new DepartmentData();
|
||||
dept3.setIdDepartment("12");
|
||||
dept3.setNmDepartment("経理部");
|
||||
|
||||
allData[7] = dept3;
|
||||
|
||||
DepartmentData dept4 = new DepartmentData();
|
||||
dept4.setIdDepartment("13");
|
||||
dept4.setNmDepartment("システム開発事業部");
|
||||
|
||||
allData[8] = dept4;
|
||||
|
||||
DepartmentData dept5 = new DepartmentData();
|
||||
dept5.setIdDepartment("14");
|
||||
dept5.setNmDepartment("教育事業部");
|
||||
|
||||
allData[9] = dept5;
|
||||
|
||||
DepartmentData dept6 = new DepartmentData();
|
||||
dept6.setIdDepartment("15");
|
||||
dept6.setNmDepartment("営業企画部");
|
||||
|
||||
allData[10] = dept6;
|
||||
|
||||
for (int i = 0; i < allData.length; i++) {
|
||||
System.out.println(allData[i]);
|
||||
}
|
||||
|
||||
// Employees[0].setIdEmployee("10000");
|
||||
// Employees[0].setNmEmployee("山田龍也");
|
||||
// Employees[0].setKnEmployee("ヤマダタツヤ");
|
||||
@@ -97,43 +150,43 @@ public class Main {
|
||||
// Employees[4].setIdDepartment("13");
|
||||
|
||||
//5人分の社員情報を表示
|
||||
for (int i = 0; i < Employees.length; i++) {
|
||||
System.out.println(Employees[i]);
|
||||
|
||||
}
|
||||
// for (int i = 0; i < Employees.length; i++) {
|
||||
// System.out.println(Employees[i]);
|
||||
//
|
||||
// }
|
||||
//社員データの件数を表示
|
||||
System.out.println("現在の社員データ件数:" + EmployeeData.getEmpCount() + "件");
|
||||
// System.out.println("現在の社員データ件数:" + EmployeeData.getEmpCount() + "件");
|
||||
|
||||
//社員ID検索機能
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
// Scanner scanner = new Scanner(System.in);
|
||||
|
||||
while(true) {
|
||||
System.out.println("検索したい社員IDを入力してください(終了する場合は0)");
|
||||
String id = scanner.nextLine();
|
||||
// while(true) {
|
||||
// System.out.println("検索したい社員IDを入力してください(終了する場合は0)");
|
||||
// String id = scanner.nextLine();
|
||||
|
||||
if(id.equals("0")) {
|
||||
System.out.println("システムを終了します");
|
||||
break;
|
||||
}
|
||||
// if(id.equals("0")) {
|
||||
// System.out.println("システムを終了します");
|
||||
// break;
|
||||
// }
|
||||
|
||||
boolean found = false;
|
||||
// boolean found = false;
|
||||
|
||||
for (int i = 0; i < Employees.length; i++) {
|
||||
|
||||
if(Employees[i].getPrimaryKeyValue().equals(id)) {
|
||||
System.out.println(Employees[i]);
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
// for (int i = 0; i < Employees.length; i++) {
|
||||
//
|
||||
// if(Employees[i].getPrimaryKeyValue().equals(id)) {
|
||||
// System.out.println(Employees[i]);
|
||||
// found = true;
|
||||
// break;
|
||||
// }
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
if(found == false) {
|
||||
System.out.println("該当する社員が見つかりませんでした");
|
||||
}
|
||||
}
|
||||
// }
|
||||
//
|
||||
// if(found == false) {
|
||||
// System.out.println("該当する社員が見つかりませんでした");
|
||||
// }
|
||||
// }
|
||||
// Employees[0].showInfo();
|
||||
//
|
||||
// System.out.println(Employees.idEmployee);
|
||||
|
||||
Reference in New Issue
Block a user