最終日

This commit is contained in:
2026-10-20 16:43:29 +09:00
parent 24aa555e45
commit b17babd071
2 changed files with 119 additions and 51 deletions

View File

@@ -1,5 +1,5 @@
public class EmployeeData {
public class EmployeeData extends BaseData {
private String idEmployee;
private String nmEmployee;
private String knEmployee;
@@ -8,81 +8,61 @@
private String idDepartment;
private static int empCount = 0;
public String getIdEmployee() {
public String getIdEmployee() {
return idEmployee;
}
public void setIdEmployee(String idEmployee) {
public void setIdEmployee(String idEmployee) {
if (idEmployee == null || idEmployee == " " ||idEmployee == " " || idEmployee.isEmpty()) {
System.out.println("社員IDが空のため設定できませんでした");
return;
}
this.idEmployee = idEmployee;
}
public String getNmEmployee() {
return nmEmployee;
}
public void setNmEmployee(String nmEmployee) {
if (nmEmployee == null || nmEmployee == " " || nmEmployee == " " || nmEmployee.isEmpty()){
System.out.println("社員名が空のため設定できませんでした");
return;
}
this.nmEmployee = nmEmployee;
}
public String getKnEmployee() {
return knEmployee;
}
public void setKnEmployee(String knEmployee) {
this.knEmployee = knEmployee;
}
public String getMailAddress() {
return mailAddress;
}
public void setMailAddress(String mailAddress) {
this.mailAddress = mailAddress;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
@@ -92,6 +72,7 @@
public String getIdDepartment() {
return idDepartment;
}
@@ -102,8 +83,22 @@
public void setIdDepartment(String idDepartment) {
this.idDepartment = idDepartment;
}
public boolean isMatchId(String id) {
if (this.idEmployee != null && this.idEmployee.equals(id)) {
return true;
} else {
return false;
}
}
public void showInfo() {
System.out.println(this.toString());
}
@Override
@@ -113,14 +108,35 @@
}
public EmployeeData() {
empCount++;
}
public EmployeeData(String idEmployee, String nmEmployee, String knEmployee,String mailAddress, String password, String idDepartment) {
setIdEmployee(idEmployee);
setNmEmployee(nmEmployee);
setKnEmployee(knEmployee);
setMailAddress(mailAddress);
setPassword(password);
setIdDepartment(idDepartment);
this.setIdEmployee(idEmployee);
this.setNmEmployee(nmEmployee);
this.setKnEmployee(knEmployee);
this.setMailAddress(mailAddress);
this.setPassword(password);
this.setIdDepartment(idDepartment);
empCount++;
}
static int getEmpCount() {
return empCount;
}
@Override
public String toCSV() {
return getIdEmployee() + "," + getNmEmployee() + "," + getKnEmployee() + "," + getMailAddress() + "," + getPassword() + "," + getIdDepartment();
}
@Override
public String getPrimaryKeyValue(){
return this.idEmployee;
}
}

View File

@@ -1,9 +1,11 @@
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ
EmployeeData[] employees = new EmployeeData[5];
BaseData[] employees = new BaseData[5];
employees[0] = new EmployeeData("10000", "山田龍也", "ヤマダタツヤ", "yamada@hoge.jp", "aaa", "10");
employees[1] = new EmployeeData("10001", "高橋準", "タカハシジュン", "jtaka@hoge.jp", "bbb", "10");
@@ -12,9 +14,59 @@ public class Main {
employees[4] = new EmployeeData("10004", "三宅武", "ミヤケタケシ", "miya@hoge.jp", "eee", "13");
for (int i = 0; i < employees.length; i++) {
System.out.println(employees[i]);
//System.out.println(employees[i]);
}
System.out.println("現在のデータ件数:"+EmployeeData.getEmpCount()+"件");
while (true) {
//Scannerを使って、
Scanner scanner = new Scanner(System.in);
//「検索したい社員IDを入力してください」と表示し
System.out.println("検索したい社員IDを入力してください(終了する場合は0)");
//キーボード入力を受け取る
String idEmployee = scanner.next();
if ("0".equals(idEmployee)) {
System.out.println("システムを終了します");
break;
}
//employees配列をfor文で1件ずつ確認し
for(int i = 0; i < employees.length; i++) {
if (((EmployeeData) employees[i]).isMatchId(idEmployee)) {
//一致する社員が見つかったら、その社員のshowInfoメソッドを呼び出す
((EmployeeData) employees[i]).showInfo();
}
else {
//
System.out.println("検索したいIDが見つかりませんでした");
break;
}
}
}
//System.out.println(employees[0].toCSV());
//System.out.println(employees[0].getPrimaryKeyValue());
}