2 Commits

Author SHA1 Message Date
a7162f1b2e Revert "no message"
This reverts commit e4cf7bed2e.
2026-10-23 09:24:52 +09:00
e4cf7bed2e no message 2026-10-22 17:09:26 +09:00
10 changed files with 10 additions and 437 deletions

View File

@@ -1,7 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="lib" path="実行例/em_oop.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>

1
.gitignore vendored
View File

@@ -1 +0,0 @@
/bin/

View File

@@ -1,23 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>development-empmanager</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.validation.validationbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View File

@@ -1,7 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.baseBrowserLibrary"/>
<classpathentry kind="src" path=""/>
<classpathentry kind="output" path=""/>
</classpath>

View File

@@ -1 +0,0 @@
org.eclipse.wst.jsdt.launching.JRE_CONTAINER

View File

@@ -1 +0,0 @@
Global

View File

@@ -1,141 +0,0 @@
package com.rhizome.example.access;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import com.rhizome.example.data.BaseData;
import com.rhizome.example.data.DepartmentData;
public class DepartmentAccess extends BaseAccess{
private static final String DEPARTMENT_FILEPATH = "file/DepartmentData.csv";
public DepartmentAccess() {
super(DEPARTMENT_FILEPATH);
}
public List<BaseData> DepSelectAll() throws FileNotFoundException {
//全件データ
List<BaseData> allList = new ArrayList<>();
//取得用リスト(CSV形式)
List<String> csvList = readData();
for (String line : csvList) {
DepartmentData department = new DepartmentData();
String[] columns = line.split(",");
department.setIdDepartment(columns[0]);
department.setNmDepartment(columns[1]);
allList.add(department);
}
return allList;
}
@Override
public List<BaseData> selectById(String key) throws FileNotFoundException {
//全件データ
List<BaseData> allList = new ArrayList<>();
//取得用リスト(CSV形式)
List<String> csvList = readData();
for (String line : csvList) {
DepartmentData department = new DepartmentData();
String[] columns = line.split(",");
department.setIdDepartment(columns[0]);
department.setNmDepartment(columns[1]);
allList.add(department);
}
//IDでの抽出データ
List<BaseData> selectList = new ArrayList<>();
for (BaseData department : allList) {
if (department.getPrimaryKeyValue().equals(key)) {
selectList.add(department);
}
}
return selectList;
}
@Override
public void insert(BaseData data) throws IOException {
//CSVファイルに追記する
addData(data);
}
@Override
public void update(BaseData updateData) throws IOException {
//更新後データリスト
List<BaseData> updatedList = new ArrayList<>();
//全件取得し、更新データを反映する
List<BaseData> allList = new ArrayList<>();
//取得用リスト(CSV形式)
List<String> csvList = readData();
for (String line : csvList) {
DepartmentData department = new DepartmentData();
String[] columns = line.split(",");
department.setIdDepartment(columns[0]);
department.setNmDepartment(columns[1]);
allList.add(department);
}
for (BaseData department : allList) {
if(department.getPrimaryKeyValue().equals(updateData.getPrimaryKeyValue())) {
//指定されたデータとキーが一致するデータの場合、更新データを設定
updatedList.add(updateData);
} else {
//上記以外は取得したデータをそのまま設定
updatedList.add(department);
}
}
//ファイル上書き処理
updateData(updatedList);
}
@Override
public void delete(String key) throws IOException {
//全件から削除データを除いたリスト
List<BaseData> deletedList = new ArrayList<>();
//全件取得し、keyに該当するデータをリストから削除する
//全件データ
List<BaseData> allList = new ArrayList<>();
//取得用リスト(CSV形式)
List<String> csvList = readData();
for (String line : csvList) {
DepartmentData department= new DepartmentData();
String[] columns = line.split(",");
department.setIdDepartment(columns[0]);
department.setNmDepartment(columns[1]);
allList.add(department);
}
for (BaseData department : allList) {
if(!department.getPrimaryKeyValue().equals(key)) {
deletedList.add(department);
}
}
//ファイル上書き処理
updateData(deletedList);
}
}

View File

@@ -16,29 +16,6 @@ public class EmployeeAccess extends BaseAccess {
super(EMPDATA_FILEPATH);
}
public List<BaseData> empSelectAll() throws FileNotFoundException {
//全件データ
List<BaseData> allList = new ArrayList<>();
//取得用リスト(CSV形式)
List<String> csvList = readData();
for (String line : csvList) {
EmployeeData employee = new EmployeeData();
String[] columns = line.split(",");
employee.setIdEmployee(columns[0]);
employee.setNmEmployee(columns[1]);
employee.setKnEmployee(columns[2]);
employee.setMailAddress(columns[3]);
employee.setPassword(columns[4]);
employee.setIdDepartment(columns[5]);
allList.add(employee);
}
return allList;
}
@Override
public List<BaseData> selectById(String key) throws FileNotFoundException {
//全件データ
@@ -150,6 +127,4 @@ public class EmployeeAccess extends BaseAccess {
updateData(deletedList);
}
}

View File

@@ -1,36 +0,0 @@
package com.rhizome.example.data;
public class DepartmentData extends BaseData{
/** 役職ID */
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();
}
}

View File

@@ -5,16 +5,13 @@ import java.io.IOException;
import java.util.List;
import java.util.Scanner;
import com.rhizome.example.access.DepartmentAccess;
import com.rhizome.example.access.EmployeeAccess;
import com.rhizome.example.data.BaseData;
import com.rhizome.example.data.DepartmentData;
import com.rhizome.example.data.EmployeeData;
public class Main {
static Scanner sc = new Scanner(System.in);
private boolean employeeMode = true;
/**
* 処理開始位置
*
@@ -22,10 +19,9 @@ public class Main {
*/
public static void main(String[] args) {
System.out.println("システムを開始します");
Main main = new Main();
while (true) {
try {
main.start();
new Main().start();
} catch (Exception e) {
System.out.println("予期せぬエラーが発生しました");
e.printStackTrace();
@@ -39,48 +35,24 @@ public class Main {
*
*/
public void start() throws IOException {
System.out.println();
System.out.println("1:検索 2:登録 3:更新 4:削除 9:データ切り替え 0:終了 "
+ "(管理対象:"
+(employeeMode ? "Employee" : "Department")
+ ")");
System.out.println("1:検索 2:登録 3:更新 4:削除 0:終了");
String ope = sc.nextLine();
switch (ope) {
case "1": //検索
if(employeeMode) {
start1();
}else {
start2();
}
empSelect();
break;
case "2": //登録
if(employeeMode) {
empInsert();
}else {
depInsert();
}
empInsert();
break;
case "3": //更新
if(employeeMode) {
empUpdate();
}else {
depUpdate();
}
empUpdate();
break;
case "4": //削除
if(employeeMode) {
empDelete();
}else {
depDelete();
}
empDelete();
break;
case "9": //データ切り替え
employeeMode = !employeeMode;
break;
case "0": //終了
case "0": //修了
System.out.println("システムを終了します");
System.exit(0);
default:
@@ -94,25 +66,6 @@ public class Main {
*
* @throws FileNotFoundException
*/
public void start1() throws IOException {
System.out.println();
System.out.println("1:全検索 2:条件検索");
String ope = sc.nextLine();
switch (ope) {
case "1": //全検索
//全出力
empSelectAll();
break;
case "2": //条件検索
empSelect();
break;
default:
//戻る
break;
}
}
public void empSelect() throws FileNotFoundException {
EmployeeAccess ea = new EmployeeAccess();
List<BaseData> list;
@@ -255,142 +208,4 @@ public class Main {
}
return str;
}
public void empSelectAll() throws FileNotFoundException {
EmployeeAccess ea = new EmployeeAccess();
List<BaseData> list = ea.empSelectAll();
for (BaseData employee : list) {
System.out.println(employee.toString());
}
}
//Department
public void start2() throws IOException {
System.out.println();
System.out.println("1:全検索 2:条件検索");
String ope = sc.nextLine();
switch (ope) {
case "1": //全検索
//全出力
DepSelectAll();
break;
case "2": //条件検索
depSelect();
break;
default:
//戻る
break;
}
}
public void depSelect() throws FileNotFoundException {
DepartmentAccess ea = new DepartmentAccess();
List<BaseData> list;
//IDの入力および入力チェック
String id = inputCheck("ID", true);
//idに一致する社員データ取得
list = ea.selectById(id);
if (list.size() == 0) { //取得結果が0件の場合
System.out.println("入力された値で情報がみつかりませんでした");
}
//取得結果件数分、データをタブ区切りで出力する
for (BaseData department : list) {
System.out.println(department.toString());
}
}
/**
* 社員ファイルに情報を登録する
*
* @throws IOException
*/
public void depInsert() throws IOException {
//各項目の入力および入力チェック処理
String depId = inputCheck("部署ID", true);
String depNm = inputCheck("部署名",false);
//社員データインスタンスを生成し、入力値を設定
DepartmentData department = new DepartmentData();
department.setIdDepartment(depId);
department.setNmDepartment(depNm);
DepartmentAccess ea = new DepartmentAccess();
//ファイルデータ追加処理
ea.insert(department);
System.out.println("登録が完了しました");
}
/**
* 社員ファイルの情報を更新する
*
* @throws IOException
*/
public void depUpdate() throws IOException {
DepartmentAccess ea = new DepartmentAccess();
//IDの入力および入力チェック
String id = inputCheck("ID", true);
//IDの存在チェック
if (ea.selectById(id).size() == 0) {
System.out.println("入力された値で情報がみつかりませんでした");
return;
}
//各項目の入力および入力チェック処理
String depId = inputCheck("部署ID", true);
String depNm = inputCheck("部署名", false);
//社員データインスタンスを生成し、入力値を設定
DepartmentData department = new DepartmentData();
department.setIdDepartment(depId);
department.setNmDepartment(depNm);
//ファイルデータ更新処理
ea.update(department);
System.out.println("更新が完了しました");
}
/**
* 社員ファイルの情報を削除する
*
* @throws IOException
*/
public void depDelete() throws IOException {
DepartmentAccess ea = new DepartmentAccess();
//IDの入力および入力チェック
String id = inputCheck("ID", true);
//IDの存在チェック
if (ea.selectById(id).size() == 0) {
System.out.println("入力された値で情報がみつかりませんでした");
return;
}
System.out.println("指定されたIDの情報を削除します? Y/y");
System.out.println("(Y/y以外の入力であればキャンセル)");
String yY = sc.nextLine();
if (!"y".equals(yY) && !"Y".equals(yY)) {
System.out.println("削除をキャンセルしました");
return;
}
//ファイルデータ削除処理
ea.delete(id);
System.out.println("削除が完了しました");
}
public void DepSelectAll()throws FileNotFoundException{
DepartmentAccess da = new DepartmentAccess();
List<BaseData> list = da.DepSelectAll();
for (BaseData department : list) {
System.out.println(department.toString());
}
}
}