Day1、8段回目完了
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
|
||||
public class EmployeeData extends BaseData {
|
||||
//フィールド宣言
|
||||
private String idEmployee;//社員ID
|
||||
@@ -57,14 +56,14 @@ public class EmployeeData extends BaseData {
|
||||
}
|
||||
|
||||
//メソッド追加
|
||||
// void showInfo() {
|
||||
// System.out.println(getIdEmployee());
|
||||
// System.out.println(getNmEmployee());
|
||||
// System.out.println(getKnEmployee);
|
||||
// System.out.println(getMailAddress());
|
||||
// System.out.println(getPassword());
|
||||
// System.out.println(getIdDepartment());
|
||||
// }
|
||||
void showInfo() {
|
||||
System.out.println(getIdEmployee());
|
||||
System.out.println(getNmEmployee());
|
||||
System.out.println(getKnEmployee());
|
||||
System.out.println(getMailAddress());
|
||||
System.out.println(getPassword());
|
||||
System.out.println(getIdDepartment());
|
||||
}
|
||||
|
||||
//上記メソッドの書き換え
|
||||
@Override
|
||||
@@ -94,16 +93,17 @@ public class EmployeeData extends BaseData {
|
||||
public String toCSV() {
|
||||
return getIdEmployee() + "," + getNmEmployee() + "," + getKnEmployee() + "," + getMailAddress() + ","
|
||||
+ getPassword() + "," + getIdDepartment();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPrimaryKeyValue() {
|
||||
return this.idEmployee;
|
||||
}
|
||||
|
||||
//メソッド追加
|
||||
boolean isMatchID(String id) {
|
||||
//メソッド追加、7段目
|
||||
public boolean isMatchID(String id) {
|
||||
return idEmployee.equals(id);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class Main {
|
||||
|
||||
@@ -17,13 +18,29 @@ public class Main {
|
||||
//5段階目記載の処理呼び出し
|
||||
//employee.showInfo();
|
||||
|
||||
//for文
|
||||
for (int i = 0; i < employees.length; i++) {
|
||||
//System.out.println(employees[i]);
|
||||
System.out.println(employees[i].toCSV());
|
||||
System.out.println(employees[i].getPrimaryKeyValue());
|
||||
//employees[i].showInfo();を上記に書き換え
|
||||
//Day1、8段階目検索
|
||||
Scanner sc = new Scanner(System.in);//インスタンス化
|
||||
System.out.println("検索したい社員IDを入力してください");
|
||||
String id = sc.next();
|
||||
//boolean変数作成
|
||||
boolean result = false;
|
||||
|
||||
for (int i = 0; i < employees.length; i++) {
|
||||
if (employees[i].isMatchID(id)) {
|
||||
result = true;
|
||||
employees[i].showInfo();
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (result == false) {
|
||||
System.out.println("該当する社員が見つかりませんでした");
|
||||
}
|
||||
}
|
||||
|
||||
//for文
|
||||
//for (int i = 0; i < employees.length; i++) {
|
||||
//System.out.println(employees[i]);
|
||||
//System.out.println(employees[i].toCSV());
|
||||
//System.out.println(employees[i].getPrimaryKeyValue());
|
||||
//employees[i].showInfo();を上記に書き換え
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user