2日目_段階8
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
|
|
||||||
public class EmployeeData {
|
public class EmployeeData {
|
||||||
// public static void main(String args[]) {
|
// public static void main(String args[]) {
|
||||||
|
|
||||||
private String idEmployee;
|
private String idEmployee;
|
||||||
@@ -8,52 +8,68 @@ public class EmployeeData {
|
|||||||
private String mailAddress;
|
private String mailAddress;
|
||||||
private String password;
|
private String password;
|
||||||
private String idDepartment;
|
private String idDepartment;
|
||||||
|
|
||||||
//staticをつけたフィールドはクラス変数:全てのインスタンスで共有される変数
|
//staticをつけたフィールドはクラス変数:全てのインスタンスで共有される変数
|
||||||
public static int empCount = 0;
|
public static int empCount = 0;
|
||||||
|
|
||||||
// boolean isMatchID = isMatchId(idEmployee);//IdEmployeeが一致するか判断
|
// boolean isMatchID = isMatchId(idEmployee);//IdEmployeeが一致するか判断
|
||||||
|
|
||||||
//idEmployee「ID」を取得するgetter
|
//idEmployee「ID」を取得するgetter
|
||||||
public String getIdEmployee() {
|
public String getIdEmployee() {
|
||||||
return idEmployee;
|
return idEmployee;
|
||||||
}
|
}
|
||||||
|
|
||||||
//idEmployee「ID」を設定するsetter
|
//idEmployee「ID」を設定するsetter
|
||||||
public void setIdEmployee(String idEmployee) {
|
public void setIdEmployee(String idEmployee) {
|
||||||
this.idEmployee = idEmployee;
|
this.idEmployee = idEmployee;
|
||||||
}
|
}
|
||||||
|
|
||||||
//nmEmployee「名前」を取得するgetter
|
//nmEmployee「名前」を取得するgetter
|
||||||
public String getNmEmployee() {
|
public String getNmEmployee() {
|
||||||
return nmEmployee;
|
return nmEmployee;
|
||||||
}
|
}
|
||||||
|
|
||||||
//nmEmployee「名前」を設定するsetter
|
//nmEmployee「名前」を設定するsetter
|
||||||
public void setNmEmployee(String nmEmployee) {
|
public void setNmEmployee(String nmEmployee) {
|
||||||
this.nmEmployee = 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
|
//getKnEmployee「カタカナの名前」を取得するgetter
|
||||||
public String getKnEmployee() {
|
public String getKnEmployee() {
|
||||||
return knEmployee;
|
return knEmployee;
|
||||||
}
|
}
|
||||||
|
|
||||||
//getKnEmployee「カタカナの名前」を設定するsetter
|
//getKnEmployee「カタカナの名前」を設定するsetter
|
||||||
public void setKnEmployee(String knEmployee) {
|
public void setKnEmployee(String knEmployee) {
|
||||||
this.knEmployee = knEmployee;
|
this.knEmployee = knEmployee;
|
||||||
}
|
}
|
||||||
|
|
||||||
//メールアドレスを取得するgetter
|
//メールアドレスを取得するgetter
|
||||||
public String getMailAddress() {
|
public String getMailAddress() {
|
||||||
return mailAddress;
|
return mailAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
//メールアドレスを設定するsetter
|
//メールアドレスを設定するsetter
|
||||||
public void setMailAddress(String mailAddress) {
|
public void setMailAddress(String mailAddress) {
|
||||||
this.mailAddress = mailAddress;
|
this.mailAddress = mailAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
//パスワードを取得するgetter
|
//パスワードを取得するgetter
|
||||||
public String getPassword() {
|
public String getPassword() {
|
||||||
return password;
|
return password;
|
||||||
}
|
}
|
||||||
|
|
||||||
//パスワードを取得するsetter
|
//パスワードを取得するsetter
|
||||||
public void setPassword(String password) {
|
public void setPassword(String password) {
|
||||||
this.password = password;
|
this.password = password;
|
||||||
@@ -63,19 +79,17 @@ public class EmployeeData {
|
|||||||
public String getIdDepartment() {
|
public String getIdDepartment() {
|
||||||
return idDepartment;
|
return idDepartment;
|
||||||
}
|
}
|
||||||
|
|
||||||
//IdDepartmentを取得するsetter
|
//IdDepartmentを取得するsetter
|
||||||
public void setIdDepartment(String idDepartment) {
|
public void setIdDepartment(String idDepartment) {
|
||||||
this.idDepartment = idDepartment;
|
this.idDepartment = idDepartment;
|
||||||
}
|
}
|
||||||
|
|
||||||
//メソッド名:isMatchId 引数:String id 戻り値:boolean ID一致ならtrue,違えばfalse
|
//メソッド名:isMatchId 引数:String id 戻り値:boolean ID一致ならtrue,違えばfalse
|
||||||
public boolean isMatchId(String id) {
|
public boolean isMatchId(String id) {
|
||||||
return this.idEmployee.equals(id);
|
return this.idEmployee.equals(id);
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public EmployeeData(String idEmployee, String nmEmployee,
|
public EmployeeData(String idEmployee, String nmEmployee,
|
||||||
String knEmployee, String mailAddress, String password, String idDepartment) {
|
String knEmployee, String mailAddress, String password, String idDepartment) {
|
||||||
@@ -85,18 +99,17 @@ public class EmployeeData {
|
|||||||
this.mailAddress = mailAddress;
|
this.mailAddress = mailAddress;
|
||||||
this.password = password;
|
this.password = password;
|
||||||
this.idDepartment = idDepartment;
|
this.idDepartment = idDepartment;
|
||||||
empCount++;
|
empCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// public boolean isMatchId(String id) {
|
// public boolean isMatchId(String id) {
|
||||||
//// if(idEmployee equals )
|
//// if(idEmployee equals )
|
||||||
// {
|
// {
|
||||||
//
|
//
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
|
||||||
// public String Employee(String idEmployee) {
|
// public String Employee(String idEmployee) {
|
||||||
// this.idEmployee= idEmployee;
|
// this.idEmployee= idEmployee;
|
||||||
// }
|
// }
|
||||||
@@ -105,23 +118,22 @@ public class EmployeeData {
|
|||||||
empCount++;
|
empCount++;
|
||||||
// TODO 自動生成されたコンストラクター・スタブ
|
// TODO 自動生成されたコンストラクター・スタブ
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getEmpCount() { //empCountの値を返せるようにする
|
public static int getEmpCount() { //empCountの値を返せるようにする
|
||||||
return empCount;
|
return empCount;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// void showinfo() { //showinfo->toStringにメソッド名変更 + アクセス修飾子publicつける
|
// void showinfo() { //showinfo->toStringにメソッド名変更 + アクセス修飾子publicつける
|
||||||
// // this.idEmployee = idEmployee;
|
// // this.idEmployee = idEmployee;
|
||||||
// System.out.println(this.idEmployee + "\t" + this.nmEmployee + "\t" + this.knEmployee + "\t" + this.mailAddress
|
// System.out.println(this.idEmployee + "\t" + this.nmEmployee + "\t" + this.knEmployee + "\t" + this.mailAddress
|
||||||
// + "\t" + this.password + "\t" + this.idDepartment);
|
// + "\t" + this.password + "\t" + this.idDepartment);
|
||||||
//
|
//
|
||||||
// }
|
// }
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return (this.idEmployee +"\t" + this.nmEmployee + "\t" + this.knEmployee + "\t" + this.mailAddress
|
return (this.idEmployee + "\t" + this.nmEmployee + "\t" + this.knEmployee + "\t" + this.mailAddress
|
||||||
+ "\t" + this.password + "\t" + this.idDepartment);
|
+ "\t" + this.password + "\t" + this.idDepartment);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,9 +15,8 @@ public class Main {
|
|||||||
// employees[0] = new EmployeeData();
|
// employees[0] = new EmployeeData();
|
||||||
|
|
||||||
employees[0] = new EmployeeData("10000", "山田龍也", "ヤマダタツヤ", "yamada@hoge.jp", "aaa", "10");
|
employees[0] = new EmployeeData("10000", "山田龍也", "ヤマダタツヤ", "yamada@hoge.jp", "aaa", "10");
|
||||||
|
|
||||||
// employees[0].setIdEmployee("1000"); //private 後 に使用する!!
|
// employees[0].setIdEmployee("1000"); //private 後 に使用する!!
|
||||||
// employees[0].setNmEmployee("山田龍也");
|
employees[0].setNmEmployee(""); //段階 8 確認用
|
||||||
// employees[0].setKnEmployee("ヤマダタツヤ");
|
// employees[0].setKnEmployee("ヤマダタツヤ");
|
||||||
// employees[0].setMailAddress("yamada@hoge.jp");
|
// employees[0].setMailAddress("yamada@hoge.jp");
|
||||||
// employees[0].setPassword("aaa");
|
// employees[0].setPassword("aaa");
|
||||||
@@ -84,7 +83,7 @@ public class Main {
|
|||||||
// employees[3].idDepartment = "12";
|
// employees[3].idDepartment = "12";
|
||||||
// //
|
// //
|
||||||
// employees[4] = new EmployeeData();
|
// 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].setIdEmployee("10004");
|
||||||
// employees[4].setNmEmployee("三宅武");
|
// employees[4].setNmEmployee("三宅武");
|
||||||
@@ -99,6 +98,8 @@ public class Main {
|
|||||||
// employees[4].mailAddress = "miya@hoge.jp";
|
// employees[4].mailAddress = "miya@hoge.jp";
|
||||||
// employees[4].password = "eee";
|
// employees[4].password = "eee";
|
||||||
// employees[4].idDepartment = "13";
|
// employees[4].idDepartment = "13";
|
||||||
|
|
||||||
|
//employees[5]= new EmployeeData("10005", , "タカヤマアカネ", "takayamaa@hoge.jp", "taka", "14");
|
||||||
|
|
||||||
// Scanner scanner = new Scanner(System.in); //8段階目!スキャナー作成
|
// Scanner scanner = new Scanner(System.in); //8段階目!スキャナー作成
|
||||||
// while (true) { //while(true)- 9段階目課題
|
// while (true) { //while(true)- 9段階目課題
|
||||||
@@ -129,12 +130,14 @@ public class Main {
|
|||||||
// }
|
// }
|
||||||
// //Scannerを閉じる
|
// //Scannerを閉じる
|
||||||
// scanner.close();
|
// scanner.close();
|
||||||
|
|
||||||
|
|
||||||
System.out.println(employees[0]);
|
System.out.println(employees[0]);
|
||||||
System.out.println(employees[1]);
|
System.out.println(employees[1]);
|
||||||
System.out.println(employees[2]);
|
System.out.println(employees[2]);
|
||||||
System.out.println(employees[3]);
|
System.out.println(employees[3]);
|
||||||
System.out.println(employees[4]);
|
System.out.println(employees[4]);
|
||||||
|
// System.out.println(employees[5]);
|
||||||
//5人分のインスタンスをすべて生成し終えた後にクラス名から呼び出し、件数表示
|
//5人分のインスタンスをすべて生成し終えた後にクラス名から呼び出し、件数表示
|
||||||
System.out.println("現在の社員データ件数:" + EmployeeData.empCount +"件");
|
System.out.println("現在の社員データ件数:" + EmployeeData.empCount +"件");
|
||||||
// employees[0].showinfo();
|
// employees[0].showinfo();
|
||||||
|
|||||||
Reference in New Issue
Block a user