2日目_段階8

This commit is contained in:
2026-09-24 12:34:11 +09:00
parent b13acdba05
commit 8efaa1341f
2 changed files with 59 additions and 44 deletions

View File

@@ -1,5 +1,5 @@
public class EmployeeData {
public class EmployeeData {
// public static void main(String args[]) {
private String idEmployee;
@@ -10,14 +10,15 @@ public class EmployeeData {
private String idDepartment;
//staticをつけたフィールドはクラス変数:全てのインスタンスで共有される変数
public static int empCount = 0;
public static int empCount = 0;
// boolean isMatchID = isMatchId(idEmployee);//IdEmployeeが一致するか判断
// boolean isMatchID = isMatchId(idEmployee);//IdEmployeeが一致するか判断
//idEmployee「ID」を取得するgetter
public String getIdEmployee() {
return idEmployee;
}
//idEmployee「ID」を設定するsetter
public void setIdEmployee(String idEmployee) {
this.idEmployee = idEmployee;
@@ -27,15 +28,28 @@ public class EmployeeData {
public String getNmEmployee() {
return nmEmployee;
}
//nmEmployee「名前」を設定するsetter
public void setNmEmployee(String nmEmployee) {
this.nmEmployee = nmEmployee.trim();
if (nmEmployee == null || nmEmployee.trim().isEmpty()) {
System.out.println("社員名が空のため設定できませんでした");
return;
}
this.nmEmployee = nmEmployee;
// this.nmEmployee = nmEmployee.trim(); //前後の空白削除
// this.nmEmployee = null;
// if(nmEmployee != null && nmEmployee.isEmpty()) {
// System.out.println("社員名が空のため設定できませんでした");
}
//getKnEmployee「カタカナの名前」を取得するgetter
public String getKnEmployee() {
return knEmployee;
}
//getKnEmployee「カタカナの名前」を設定するsetter
public void setKnEmployee(String knEmployee) {
this.knEmployee = knEmployee;
@@ -45,6 +59,7 @@ public class EmployeeData {
public String getMailAddress() {
return mailAddress;
}
//メールアドレスを設定するsetter
public void setMailAddress(String mailAddress) {
this.mailAddress = mailAddress;
@@ -54,6 +69,7 @@ public class EmployeeData {
public String getPassword() {
return password;
}
//パスワードを取得するsetter
public void setPassword(String password) {
this.password = password;
@@ -63,6 +79,7 @@ public class EmployeeData {
public String getIdDepartment() {
return idDepartment;
}
//IdDepartmentを取得するsetter
public void setIdDepartment(String idDepartment) {
this.idDepartment = idDepartment;
@@ -74,9 +91,6 @@ public class EmployeeData {
}
public EmployeeData(String idEmployee, String nmEmployee,
String knEmployee, String mailAddress, String password, String idDepartment) {
this.idEmployee = idEmployee;
@@ -85,17 +99,16 @@ public class EmployeeData {
this.mailAddress = mailAddress;
this.password = password;
this.idDepartment = idDepartment;
empCount++;
empCount++;
}
// public boolean isMatchId(String id) {
//// if(idEmployee equals )
// {
//
// }
//
// }
// public boolean isMatchId(String id) {
//// if(idEmployee equals )
// {
//
// }
//
// }
// public String Employee(String idEmployee) {
// this.idEmployee= idEmployee;
@@ -111,17 +124,16 @@ public class EmployeeData {
}
// void showinfo() { //showinfo->toStringにメソッド名変更 + アクセス修飾子publicつける
// // this.idEmployee = idEmployee;
// System.out.println(this.idEmployee + "\t" + this.nmEmployee + "\t" + this.knEmployee + "\t" + this.mailAddress
// + "\t" + this.password + "\t" + this.idDepartment);
//
// }
@Override
public String toString() {
return (this.idEmployee +"\t" + this.nmEmployee + "\t" + this.knEmployee + "\t" + this.mailAddress
+ "\t" + this.password + "\t" + this.idDepartment);
}
// void showinfo() { //showinfo->toStringにメソッド名変更 + アクセス修飾子publicつける
// // this.idEmployee = idEmployee;
// System.out.println(this.idEmployee + "\t" + this.nmEmployee + "\t" + this.knEmployee + "\t" + this.mailAddress
// + "\t" + this.password + "\t" + this.idDepartment);
//
// }
@Override
public String toString() {
return (this.idEmployee + "\t" + this.nmEmployee + "\t" + this.knEmployee + "\t" + this.mailAddress
+ "\t" + this.password + "\t" + this.idDepartment);
}
}

View File

@@ -15,9 +15,8 @@ public class Main {
// employees[0] = new EmployeeData();
employees[0] = new EmployeeData("10000", "山田龍也", "ヤマダタツヤ", "yamada@hoge.jp", "aaa", "10");
// employees[0].setIdEmployee("1000"); //private 後 に使用する!!
// employees[0].setNmEmployee("山田龍也");
employees[0].setNmEmployee(""); //段階 8 確認用
// employees[0].setKnEmployee("ヤマダタツヤ");
// employees[0].setMailAddress("yamada@hoge.jp");
// employees[0].setPassword("aaa");
@@ -84,7 +83,7 @@ public class Main {
// employees[3].idDepartment = "12";
// //
// employees[4] = new EmployeeData();
employees[4] = new EmployeeData("10004", "三宅武", "ミヤケタケシ", "miya@hoge.jp", "eee", "13");
employees[4] = new EmployeeData("10004", "aa", "ミヤケタケシ", "miya@hoge.jp", "eee", "13");
// employees[4].setIdEmployee("10004");
// employees[4].setNmEmployee("三宅武");
@@ -100,6 +99,8 @@ public class Main {
// employees[4].password = "eee";
// employees[4].idDepartment = "13";
//employees[5]= new EmployeeData("10005", , "タカヤマアカネ", "takayamaa@hoge.jp", "taka", "14");
// Scanner scanner = new Scanner(System.in); //8段階目!スキャナー作成
// while (true) { //while(true)- 9段階目課題
// System.out.println("検索したい社員IDを入力してください"); //検索するID入力
@@ -130,11 +131,13 @@ public class Main {
// //Scannerを閉じる
// scanner.close();
System.out.println(employees[0]);
System.out.println(employees[1]);
System.out.println(employees[2]);
System.out.println(employees[3]);
System.out.println(employees[4]);
// System.out.println(employees[5]);
//5人分のインスタンスをすべて生成し終えた後にクラス名から呼び出し、件数表示
System.out.println("現在の社員データ件数:" + EmployeeData.empCount +"件");
// employees[0].showinfo();