追加課題(登録処理まで完了)
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
実行例(追加問題含め)/em_oop.jar
|
||||
6
DepartmentData.csv
Normal file
6
DepartmentData.csv
Normal file
@@ -0,0 +1,6 @@
|
||||
10,役員
|
||||
11,人事・総務部
|
||||
12,経理部
|
||||
13,システム開発事業部
|
||||
14,教育事業部
|
||||
15,営業企画部
|
||||
|
11
EmployeeData.csv
Normal file
11
EmployeeData.csv
Normal file
@@ -0,0 +1,11 @@
|
||||
10000,山田龍也,ヤマダタツヤ,yamada@hoge.jp,aaa,10
|
||||
10001,高橋準,タカハシジュン,jtaka@hoge.jp,bbb,10
|
||||
10002,麻枝史明,マエダフミアキ,fmak@hoge.jp,ccc,11
|
||||
10003,丸戸章介,マルトショウスケ,marusyo@hoge.jp,ddd,12
|
||||
10004,三宅武,ミヤケタケシ,miya@hoge.jp,eee,13
|
||||
10005,丸井悠,マルイハルカ,haru@hoge.jp,fff,13
|
||||
10006,涼元香織,スズモトカオリ,suzumoto@hoge.jp,ggg,13
|
||||
10007,葉山稔,ハヤマミノル,mhayama@hoge.jp,hhh,14
|
||||
10008,川上朱里,カワカミアカリ,kawakami@hoge.jp,iii,14
|
||||
10009,杉井肇,スギイハジメ,sugi@hoge.jp,jjj,15
|
||||
12345,石原,イシハラ,tesr,test,10
|
||||
|
10
実行例_20261020/.classpath
Normal file
10
実行例_20261020/.classpath
Normal file
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-21">
|
||||
<attributes>
|
||||
<attribute name="module" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
17
実行例_20261020/.project
Normal file
17
実行例_20261020/.project
Normal file
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>実行例_20261020</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
2
実行例_20261020/.settings/org.eclipse.core.resources.prefs
Normal file
2
実行例_20261020/.settings/org.eclipse.core.resources.prefs
Normal file
@@ -0,0 +1,2 @@
|
||||
eclipse.preferences.version=1
|
||||
encoding/<project>=UTF-8
|
||||
11
実行例_20261020/.settings/org.eclipse.jdt.core.prefs
Normal file
11
実行例_20261020/.settings/org.eclipse.jdt.core.prefs
Normal file
@@ -0,0 +1,11 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=21
|
||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||
org.eclipse.jdt.core.compiler.compliance=21
|
||||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
|
||||
org.eclipse.jdt.core.compiler.release=enabled
|
||||
org.eclipse.jdt.core.compiler.source=21
|
||||
BIN
実行例_20261020/bin/BaseData.class
Normal file
BIN
実行例_20261020/bin/BaseData.class
Normal file
Binary file not shown.
BIN
実行例_20261020/bin/DepartmentData.class
Normal file
BIN
実行例_20261020/bin/DepartmentData.class
Normal file
Binary file not shown.
BIN
実行例_20261020/bin/EmployeeData.class
Normal file
BIN
実行例_20261020/bin/EmployeeData.class
Normal file
Binary file not shown.
BIN
実行例_20261020/bin/Main.class
Normal file
BIN
実行例_20261020/bin/Main.class
Normal file
Binary file not shown.
10
実行例_20261020/src/BaseData.java
Normal file
10
実行例_20261020/src/BaseData.java
Normal file
@@ -0,0 +1,10 @@
|
||||
|
||||
|
||||
public abstract class BaseData {
|
||||
|
||||
public abstract String toString();
|
||||
|
||||
public abstract String toCSV();
|
||||
|
||||
public abstract String getPrimaryKeyValue();
|
||||
}
|
||||
38
実行例_20261020/src/DepartmentData.java
Normal file
38
実行例_20261020/src/DepartmentData.java
Normal file
@@ -0,0 +1,38 @@
|
||||
|
||||
|
||||
public class DepartmentData extends BaseData {
|
||||
|
||||
private String idDepartment;
|
||||
private String nmDepartment;
|
||||
|
||||
public String getIdDepartment() {
|
||||
return idDepartment;
|
||||
}
|
||||
|
||||
public void setIdDepartment(String idDepartment) {
|
||||
this.idDepartment = idDepartment;
|
||||
}
|
||||
|
||||
public String getNmDepartment() {
|
||||
return nmDepartment;
|
||||
}
|
||||
|
||||
public void setNmDepartment(String nmDepartment) {
|
||||
this.nmDepartment = nmDepartment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getIdDepartment() + "\t" + getNmDepartment();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toCSV() {
|
||||
return getIdDepartment() + "," + getNmDepartment();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPrimaryKeyValue() {
|
||||
return getIdDepartment();
|
||||
}
|
||||
}
|
||||
147
実行例_20261020/src/EmployeeData.java
Normal file
147
実行例_20261020/src/EmployeeData.java
Normal file
@@ -0,0 +1,147 @@
|
||||
|
||||
|
||||
public class EmployeeData extends BaseData {
|
||||
//社員ID
|
||||
private String idEmployee;
|
||||
//社員名
|
||||
private String nmEmployee;
|
||||
//社員名カナ
|
||||
private String knEmployee;
|
||||
//メールアドレス
|
||||
private String mailAddress;
|
||||
//パスワード
|
||||
private String password;
|
||||
//部署ID
|
||||
private String idDepartment;
|
||||
//社員データ件数
|
||||
private static int empCount = 0;
|
||||
//コンストラクタ
|
||||
public EmployeeData() {
|
||||
empCount++;
|
||||
}
|
||||
//コンストラクタ
|
||||
public EmployeeData(
|
||||
String idEmployee,
|
||||
String nmEmployee,
|
||||
String knEmployee,
|
||||
String mailAddress,
|
||||
String password,
|
||||
String idDepartment) {
|
||||
|
||||
this.setIdEmployee(idEmployee);
|
||||
this.setNmEmployee(nmEmployee);
|
||||
this.setKnEmployee(knEmployee);
|
||||
this.setMailAddress(mailAddress);
|
||||
this.setPassword(password);
|
||||
this.setIdDepartment(idDepartment);
|
||||
|
||||
empCount++;
|
||||
}
|
||||
|
||||
//ゲッター
|
||||
public String getIdEmployee() {
|
||||
return idEmployee;
|
||||
}
|
||||
public String getNmEmployee() {
|
||||
return nmEmployee;
|
||||
}
|
||||
public String getKnEmployee() {
|
||||
return knEmployee;
|
||||
}
|
||||
public String getMailAddress() {
|
||||
return mailAddress;
|
||||
}
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
public String getIdDepartment() {
|
||||
return idDepartment;
|
||||
}
|
||||
//セッター
|
||||
public void setIdEmployee(String idEmployee) {
|
||||
|
||||
if (idEmployee == null) {
|
||||
System.out.println("社員IDが空のため設定できませんでした");
|
||||
return;
|
||||
}
|
||||
|
||||
if (idEmployee.trim().isEmpty()) {
|
||||
System.out.println("社員IDが空のため設定できませんでした");
|
||||
return;
|
||||
}
|
||||
|
||||
this.idEmployee = idEmployee;
|
||||
}
|
||||
|
||||
public void setNmEmployee(String nmEmployee) {
|
||||
|
||||
if (nmEmployee == null) {
|
||||
System.out.println("社員名が空のため設定できませんでした");
|
||||
return;
|
||||
}
|
||||
|
||||
if (nmEmployee.trim().isEmpty()) {
|
||||
System.out.println("社員名が空のため設定できませんでした");
|
||||
return;
|
||||
}
|
||||
|
||||
this.nmEmployee = nmEmployee;
|
||||
}
|
||||
|
||||
public void setKnEmployee(String knEmployee) {
|
||||
this.knEmployee = knEmployee;
|
||||
}
|
||||
|
||||
public void setMailAddress(String mailAddress) {
|
||||
this.mailAddress = mailAddress;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public void setIdDepartment(String idDepartment) {
|
||||
this.idDepartment = idDepartment;
|
||||
}
|
||||
|
||||
//toString
|
||||
@Override
|
||||
public String toString() {
|
||||
|
||||
return getIdEmployee() + "\t"
|
||||
+ getNmEmployee() + "\t"
|
||||
+ getKnEmployee() + "\t"
|
||||
+ getMailAddress() + "\t"
|
||||
+ getPassword() + "\t"
|
||||
+ getIdDepartment();
|
||||
}
|
||||
|
||||
//CSV形式へ変換
|
||||
@Override
|
||||
public String toCSV() {
|
||||
|
||||
return getIdEmployee() + ","
|
||||
+ getNmEmployee() + ","
|
||||
+ getKnEmployee() + ","
|
||||
+ getMailAddress() + ","
|
||||
+ getPassword() + ","
|
||||
+ getIdDepartment();
|
||||
}
|
||||
|
||||
//キー取得
|
||||
@Override
|
||||
public String getPrimaryKeyValue() {
|
||||
|
||||
return getIdEmployee();
|
||||
}
|
||||
|
||||
//ID一致判定
|
||||
public boolean isMatchId(String id) {
|
||||
return getIdEmployee().equals(id);
|
||||
}
|
||||
|
||||
//件数取得
|
||||
public static int getEmpCount() {
|
||||
return empCount;
|
||||
}
|
||||
}
|
||||
214
実行例_20261020/src/Main.java
Normal file
214
実行例_20261020/src/Main.java
Normal file
@@ -0,0 +1,214 @@
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class Main {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
|
||||
//社員データ格納用配列
|
||||
//CSVから読み込んだ社員データを格納する
|
||||
EmployeeData[] employees = new EmployeeData[100];
|
||||
|
||||
//読み込んだ件数管理用
|
||||
int count = 0;
|
||||
|
||||
// EmployeeData.csv読込
|
||||
try {
|
||||
|
||||
BufferedReader br =
|
||||
new BufferedReader(new FileReader("C:\\Users\\石原 叶大\\Documents\\em-oop\\EmployeeData.csv"));
|
||||
|
||||
String line;
|
||||
|
||||
|
||||
// CSVを1行ずつ読込
|
||||
while ((line = br.readLine()) != null) {
|
||||
|
||||
//カンマ区切りで分割
|
||||
String[] data = line.split(",");
|
||||
|
||||
// EmployeeData生成
|
||||
EmployeeData employee = new EmployeeData();
|
||||
|
||||
|
||||
//CSVの値をEmployeeDataへ設定
|
||||
employee.setIdEmployee(data[0]);
|
||||
employee.setNmEmployee(data[1]);
|
||||
employee.setKnEmployee(data[2]);
|
||||
employee.setMailAddress(data[3]);
|
||||
employee.setPassword(data[4]);
|
||||
employee.setIdDepartment(data[5]);
|
||||
|
||||
|
||||
//配列へ格納
|
||||
employees[count] = employee;
|
||||
|
||||
//件数加算
|
||||
count++;
|
||||
}
|
||||
|
||||
//ファイルクローズ
|
||||
br.close();
|
||||
|
||||
} catch (IOException e) {
|
||||
|
||||
//CSV読込失敗
|
||||
System.out.println("CSVの読み込みに失敗しました");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
//システム開始
|
||||
System.out.println("システムを開始します");
|
||||
|
||||
//ループ
|
||||
//0が入力されるまで繰り返す
|
||||
while (true) {
|
||||
|
||||
System.out.println();
|
||||
|
||||
//メニュー表示
|
||||
System.out.println("1:検索 2:登録 3:更新 4:削除 0:終了");
|
||||
|
||||
//メニュー入力
|
||||
String menu = scanner.nextLine();
|
||||
|
||||
//システム終了
|
||||
if (menu.equals("0")) {
|
||||
System.out.println("システムを終了します");
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
//検索機能
|
||||
else if (menu.equals("1")) {
|
||||
|
||||
//検索メニュー表示
|
||||
System.out.println("1:全検索 2:条件検索 それ以外:戻る");
|
||||
|
||||
String searchMenu = scanner.nextLine();
|
||||
|
||||
//全検索
|
||||
if (searchMenu.equals("1")) {
|
||||
|
||||
// 読み込んだ全社員を表示
|
||||
for (int i = 0; i < count; i++) {
|
||||
|
||||
System.out.println(employees[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//社員ID検索
|
||||
else if (searchMenu.equals("2")) {
|
||||
|
||||
//ID入力
|
||||
System.out.println("IDを入力してください");
|
||||
|
||||
String id = scanner.nextLine();
|
||||
|
||||
//検索判定
|
||||
boolean found = false;
|
||||
|
||||
//配列検索
|
||||
for (int i = 0; i < count; i++) {
|
||||
|
||||
//社員ID比較
|
||||
if (employees[i].getPrimaryKeyValue().equals(id)) {
|
||||
|
||||
//一致データ表示
|
||||
System.out.println(employees[i]);
|
||||
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//見つからなかった場合
|
||||
if (!found) {System.out.println("該当する社員が見つかりませんでした");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//社員登録機能
|
||||
else if (menu.equals("2")) {
|
||||
|
||||
//新しい社員データ生成
|
||||
EmployeeData employee = new EmployeeData();
|
||||
|
||||
//社員ID入力
|
||||
System.out.println("社員IDを入力してください");
|
||||
employee.setIdEmployee(scanner.nextLine());
|
||||
|
||||
//社員名入力
|
||||
System.out.println("社員名を入力してください");
|
||||
|
||||
employee.setNmEmployee(scanner.nextLine());
|
||||
|
||||
//フリガナ入力
|
||||
System.out.println("フリガナを入力してください");
|
||||
employee.setKnEmployee(scanner.nextLine());
|
||||
|
||||
//メールアドレス入力
|
||||
System.out.println("メールアドレスを入力してください");
|
||||
employee.setMailAddress(scanner.nextLine());
|
||||
|
||||
//パスワード入力
|
||||
System.out.println("パスワードを入力してください");
|
||||
|
||||
employee.setPassword(scanner.nextLine());
|
||||
|
||||
//部署ID入力
|
||||
System.out.println("部署IDを入力してください");
|
||||
employee.setIdDepartment(scanner.nextLine());
|
||||
|
||||
//配列へ追加
|
||||
employees[count] = employee;
|
||||
|
||||
//CSVへ追記
|
||||
try {
|
||||
PrintWriter pw =
|
||||
new PrintWriter(new FileWriter("C:\\Users\\石原 叶大\\Documents\\em-oop\\EmployeeData.csv",true));
|
||||
|
||||
//CSVに1行追加
|
||||
pw.println(employee.toCSV());
|
||||
pw.close();
|
||||
|
||||
} catch (IOException e) {
|
||||
System.out.println("CSVへの保存に失敗しました");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// 件数加算
|
||||
count++;
|
||||
|
||||
System.out.println("登録が完了しました");
|
||||
}
|
||||
|
||||
//更新機能
|
||||
//未実装あとから使う
|
||||
else if (menu.equals("3")) {
|
||||
System.out.println("更新機能は未実装です");
|
||||
}
|
||||
|
||||
//削除機能
|
||||
//未実装あとから使う
|
||||
else if (menu.equals("4")) {
|
||||
System.out.println("削除機能は未実装です");
|
||||
}
|
||||
|
||||
//入力ミス
|
||||
else {
|
||||
System.out.println("正しく入力してください");
|
||||
}
|
||||
}
|
||||
|
||||
scanner.close();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user