20261020
This commit is contained in:
7
src/main/java/BaseDate.java
Normal file
7
src/main/java/BaseDate.java
Normal file
@@ -0,0 +1,7 @@
|
||||
|
||||
public abstract class BaseDate {
|
||||
|
||||
public abstract String toString();
|
||||
public abstract String toCSV();
|
||||
public abstract String getPrimaryKeyValue();
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
public class EmployeeData {
|
||||
public class EmployeeData extends BaseDate {
|
||||
|
||||
//フィールドの宣言
|
||||
//社員ID
|
||||
@@ -14,7 +14,7 @@ public class EmployeeData {
|
||||
//部署ID
|
||||
private String idDepartment;
|
||||
|
||||
private static int empCount = 0;
|
||||
public static int empCount;
|
||||
|
||||
|
||||
//ゲッターとセッター
|
||||
@@ -33,9 +33,27 @@ public class EmployeeData {
|
||||
|
||||
|
||||
public void setNmEmployee(String nmEmployee) {
|
||||
|
||||
if(nmEmployee == null) {
|
||||
System.out.println("社員名が空のため設定できませんでした");
|
||||
|
||||
} else {
|
||||
this.nmEmployee = nmEmployee;
|
||||
}
|
||||
|
||||
//文字列前後の空白を取り除く
|
||||
String trimmednmEmployee = nmEmployee.trim();
|
||||
//文字列の長さを調べる
|
||||
int count = trimmednmEmployee.length();
|
||||
|
||||
if(count == 0) {
|
||||
System.out.println("社員名が空のため設定できませんでした");
|
||||
}else {
|
||||
this.nmEmployee = nmEmployee;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public String getKnEmployee() {
|
||||
return knEmployee;
|
||||
@@ -73,9 +91,25 @@ public class EmployeeData {
|
||||
|
||||
|
||||
public void setIdDepartment(String idDepartment) {
|
||||
if(idDepartment == null) {
|
||||
System.out.println("社員IDが空のため設定できませんでした");
|
||||
|
||||
} else {
|
||||
this.idDepartment = idDepartment;
|
||||
}
|
||||
|
||||
//文字列前後の空白を取り除く
|
||||
String trimmednmEmployee = nmEmployee.trim();
|
||||
//文字列の長さを調べる
|
||||
int count = trimmednmEmployee.length();
|
||||
|
||||
if(count == 0) {
|
||||
System.out.println("社員IDがのため設定できませんでした");
|
||||
}else {
|
||||
this.idDepartment = idDepartment;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static int getEmpCount() {
|
||||
@@ -83,23 +117,24 @@ public class EmployeeData {
|
||||
}
|
||||
|
||||
public static void setEmpCount(int empCount) {
|
||||
EmployeeData.empCount = empCount;
|
||||
EmployeeData.empCount = empCount ++;
|
||||
}
|
||||
|
||||
|
||||
//コンストラクタの作成
|
||||
public EmployeeData() {
|
||||
this.setEmpCount(empCount ++);
|
||||
|
||||
}
|
||||
|
||||
public EmployeeData(String idEmployee, String nmEmployee, String knEmployee, String mailAddress, String password, String idDepartment ) {
|
||||
public EmployeeData(String idEmployee, String nmEmployee, String knEmployee, String mailAddress, String password, String idDepartment, int empCount) {
|
||||
this.setIdEmployee(idEmployee);
|
||||
this.setNmEmployee(nmEmployee);
|
||||
this.setKnEmployee(knEmployee);
|
||||
this.setMailAddress(mailAddress);
|
||||
this.setPassword(password);
|
||||
this.setIdDepartment(idDepartment);
|
||||
this.setEmpCount(empCount ++);
|
||||
this.setEmpCount(empCount);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -116,6 +151,13 @@ public class EmployeeData {
|
||||
return getEmpCount();
|
||||
}
|
||||
|
||||
@Override public String toCSV(){
|
||||
return (getIdEmployee() +","+ getNmEmployee() +","+ getKnEmployee() +","+ getMailAddress() +","+ getPassword() +","+ getIdDepartment());
|
||||
}
|
||||
|
||||
@Override public String getPrimaryKeyValue() {
|
||||
return idEmployee;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
|
||||
public class EmployeeData {
|
||||
|
||||
//フィールドの宣言
|
||||
|
||||
//社員ID
|
||||
String idEmployee;
|
||||
//社員名
|
||||
String nmEmployee;
|
||||
//社員名カナ
|
||||
String knEmployee;
|
||||
//メールアドレス
|
||||
String mailAddress;
|
||||
//パスワード
|
||||
String password;
|
||||
//部署ID
|
||||
String idDepartment;
|
||||
|
||||
//メソッドの作成
|
||||
public void showInfo() {
|
||||
System.out.println(this.idEmployee + "\t" + this.nmEmployee + "\t" + this.knEmployee + "\t" + this.mailAddress + "\t" + this.password + "\t" + this.idDepartment);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,11 +7,11 @@ public class em_oop_20261014 {
|
||||
//インスタンスの生成
|
||||
EmployeeData[] employees = new EmployeeData[5];
|
||||
|
||||
employees[0] = new EmployeeData("10000", "山田達也", "ヤマダタツヤ","yamada@hoge.jp" ,"aaa", "10");
|
||||
employees[1] = new EmployeeData("10001","高橋準","タカハシジュン","jtaka@hoge.jp","bbb","10");
|
||||
employees[2] = new EmployeeData("10002","麻枝史明","マエダフミアキ","fmak@hoge.jp","ccc","11");
|
||||
employees[3] = new EmployeeData("10003","丸戸章介","マルトショウスケ","marusyo@hoge.jp","ddd","12");
|
||||
employees[4] = new EmployeeData("10004","三宅武","ミヤケタケシ","miya@hoge.jp","eee","13");
|
||||
employees[0] = new EmployeeData("10000", "山田達也", "ヤマダタツヤ","yamada@hoge.jp" ,"aaa", "10",0);
|
||||
employees[1] = new EmployeeData("10001","高橋準","タカハシジュン","jtaka@hoge.jp","bbb","10",1);
|
||||
employees[2] = new EmployeeData("10002","麻枝史明","マエダフミアキ","fmak@hoge.jp","ccc","11",2);
|
||||
employees[3] = new EmployeeData("10003","丸戸章介","マルトショウスケ","marusyo@hoge.jp","ddd","12",3);
|
||||
employees[4] = new EmployeeData("10004","三宅武","ミヤケタケシ","miya@hoge.jp","eee","13",4);
|
||||
|
||||
|
||||
//呼び出し
|
||||
@@ -22,7 +22,11 @@ public class em_oop_20261014 {
|
||||
System.out.println(employees[4]);
|
||||
|
||||
|
||||
System.out.println(EmployeeData.getEmpCount());
|
||||
|
||||
System.out.println("現在の社員データ件数:" + employees.length);
|
||||
|
||||
//employees.toCSV();
|
||||
//employees.getPrimaryKeyValue();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,66 +0,0 @@
|
||||
|
||||
public class em_oop_20261014 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// TODO 自動生成されたメソッド・スタブ
|
||||
|
||||
//複数の社員データをまとめて表示
|
||||
EmployeeData[] employees = new EmployeeData[5];
|
||||
|
||||
EmployeeData employees0 = new EmployeeData();
|
||||
|
||||
//employees[0]
|
||||
employees0.idEmployee = "10000";
|
||||
employees0.nmEmployee = "山田龍也";
|
||||
employees0.knEmployee = "ヤマダタツヤ";
|
||||
employees0.mailAddress = "yamada@hoge.jp";
|
||||
employees0.password = "aaa";
|
||||
employees0.idDepartment = "10";
|
||||
|
||||
|
||||
EmployeeData employees1 = new EmployeeData();
|
||||
//employees[1]
|
||||
employees1.idEmployee = "10001";
|
||||
employees1.nmEmployee = "高橋準";
|
||||
employees1.knEmployee = "タカハシジュン";
|
||||
employees1.mailAddress = "jtaka@hoge.jp";
|
||||
employees1.password = "bbb";
|
||||
employees1.idDepartment = "10";
|
||||
|
||||
EmployeeData employees2 = new EmployeeData();
|
||||
//employees[2]
|
||||
employees2.idEmployee = "10002";
|
||||
employees2.nmEmployee = "麻枝史明";
|
||||
employees2.knEmployee = "マエダフミアキ";
|
||||
employees2.mailAddress = "fmak@hoge.jp";
|
||||
employees2.password = "ccc";
|
||||
employees2.idDepartment = "11";
|
||||
|
||||
EmployeeData employees3 = new EmployeeData();
|
||||
//employees[3]
|
||||
employees3.idEmployee = "10003";
|
||||
employees3.nmEmployee = "丸戸章介";
|
||||
employees3.knEmployee = "マルトショウスケ";
|
||||
employees3.mailAddress = "marusyo@hoge.jp";
|
||||
employees3.password = "ddd";
|
||||
employees3.idDepartment = "12";
|
||||
|
||||
EmployeeData employees4 = new EmployeeData();
|
||||
//employees[4]
|
||||
employees4.idEmployee = "10004";
|
||||
employees4.nmEmployee = "三宅武";
|
||||
employees4.knEmployee = "ミヤケタケシ";
|
||||
employees4.mailAddress = "miya@hoge.jp";
|
||||
employees4.password = "eee";
|
||||
employees4.idDepartment = "13";
|
||||
|
||||
employees0.showInfo();
|
||||
employees1.showInfo();
|
||||
employees2.showInfo();
|
||||
employees3.showInfo();
|
||||
employees4.showInfo();
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user