Compare commits
6 Commits
kawara
...
127b824ceb
| Author | SHA1 | Date | |
|---|---|---|---|
| 127b824ceb | |||
| 3f20a2a872 | |||
| 19563fbbbb | |||
| 0ab032f2e3 | |||
| 91dac26b86 | |||
| 548e172d7d |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1 +1,2 @@
|
|||||||
|
/bin/
|
||||||
/build/
|
/build/
|
||||||
|
|||||||
@@ -1,9 +0,0 @@
|
|||||||
|
|
||||||
public abstract class BaseData{
|
|
||||||
public abstract String toString();
|
|
||||||
public abstract String toCSV();
|
|
||||||
public abstract String getPrimaryKeyValue();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
|
|
||||||
public class BasicCheck1 {
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
// TODO 自動生成されたメソッド・スタブ
|
|
||||||
Book book = new Book();
|
|
||||||
Book book1 = new Book();
|
|
||||||
|
|
||||||
book.title = "吾輩は猫である";
|
|
||||||
book.author = "夏目漱石";
|
|
||||||
book.price = 800;
|
|
||||||
|
|
||||||
System.out.println(book1.title);
|
|
||||||
System.out.println(book1.author);
|
|
||||||
System.out.println(book1.price);
|
|
||||||
|
|
||||||
|
|
||||||
System.out.println(book.title);
|
|
||||||
System.out.println(book.author);
|
|
||||||
System.out.println(book.price);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
|
|
||||||
public class BasicCheck2 {
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
// TODO 自動生成されたメソッド・スタブ
|
|
||||||
|
|
||||||
Student student1 = new Student(1, "鈴木一郎");
|
|
||||||
Student student2 = new Student(2, "田中花子");
|
|
||||||
Student student3 = new Student(3, "佐藤次郎");
|
|
||||||
|
|
||||||
student1.printProfile();
|
|
||||||
student2.printProfile();
|
|
||||||
student3.printProfile();
|
|
||||||
|
|
||||||
System.out.println("現在の生徒数: " + student1.getStudentCount() + "人");
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
|
|
||||||
public class BasicCheck3 {
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
// TODO 自動生成されたメソッド・スタブ
|
|
||||||
Item[] items = new Item[3];
|
|
||||||
|
|
||||||
items[0] = new Item();
|
|
||||||
items[0].setName("ノート");
|
|
||||||
items[0].setPrice(120);
|
|
||||||
items[0].setStock(50);
|
|
||||||
|
|
||||||
|
|
||||||
items[1] = new Item();
|
|
||||||
items[1].setName("消しゴム");
|
|
||||||
items[1].setPrice(80);
|
|
||||||
items[1].setStock(30);
|
|
||||||
|
|
||||||
|
|
||||||
items[2] = new Item();
|
|
||||||
items[2].setName("鉛筆");
|
|
||||||
items[2].setPrice(60);
|
|
||||||
items[2].setStock(100);
|
|
||||||
|
|
||||||
for (int i = 0; i < items.length; i++) {
|
|
||||||
items[i].sell(5);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < items.length; i++) {
|
|
||||||
System.out.println(items[i]);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
|
|
||||||
public class Book {
|
|
||||||
String title;
|
|
||||||
String author;
|
|
||||||
int price;
|
|
||||||
|
|
||||||
public Book() {
|
|
||||||
title = "タイトル未設定";
|
|
||||||
author = "著者未設定";
|
|
||||||
price = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Book(String title,String author,int price) {
|
|
||||||
this.title = title;
|
|
||||||
this.author = author;
|
|
||||||
this.price = price;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,142 +1,110 @@
|
|||||||
public class EmployeeData extends BaseData {
|
|
||||||
|
|
||||||
private String idEmployee;
|
|
||||||
private String nmEmployee;
|
|
||||||
private String knEmployee;
|
|
||||||
private String mailAddress;
|
|
||||||
private String password;
|
|
||||||
private String idDepartment;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private static int empCount = 0;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public class EmployeeData {
|
||||||
|
|
||||||
public String getIdEmployee() {
|
static final String COMPANY_NAME = "Rhizome";
|
||||||
return idEmployee;
|
private static int empCount = 0;
|
||||||
}
|
private String idEmployee;
|
||||||
|
private String nmEmployee;
|
||||||
|
private String knEmployee;
|
||||||
|
private String mailAddress;
|
||||||
|
private String password;
|
||||||
|
private String idDepartment;
|
||||||
|
|
||||||
public void setIdEmployee(String idEmployee) {
|
public EmployeeData() {
|
||||||
if (idEmployee == null || idEmployee == " " ||idEmployee == " " || idEmployee.isEmpty()) {
|
empCount++;
|
||||||
System.out.println("社員IDが空のため設定できませんでした");
|
}
|
||||||
return;
|
|
||||||
}
|
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 void setIdEmployee(String idEmployee) {
|
||||||
|
if (idEmployee.strip().length()==0) {
|
||||||
|
System.out.println("社員IDが空のため設定できませんでした");
|
||||||
|
System.exit(0);
|
||||||
|
} else {
|
||||||
this.idEmployee = idEmployee;
|
this.idEmployee = idEmployee;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
public String getNmEmployee() {
|
|
||||||
return nmEmployee;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
public String getNmEmployee() {
|
||||||
|
return nmEmployee;
|
||||||
|
}
|
||||||
|
|
||||||
public void setNmEmployee(String nmEmployee) {
|
public void setNmEmployee(String nmEmployee) {
|
||||||
if (nmEmployee == null || nmEmployee == " " || nmEmployee == " " || nmEmployee.isEmpty()){
|
if (nmEmployee.strip().length()==0) {
|
||||||
System.out.println("社員名が空のため設定できませんでした");
|
System.out.println("社員名が空のため設定できませんでした");
|
||||||
return;
|
System.exit(0);
|
||||||
}
|
} else {
|
||||||
this.nmEmployee = nmEmployee;
|
this.nmEmployee = nmEmployee;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public String getKnEmployee() {
|
public String getKnEmployee() {
|
||||||
return knEmployee;
|
return knEmployee;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setKnEmployee(String knEmployee) {
|
public void setKnEmployee(String knEmployee) {
|
||||||
this.knEmployee = knEmployee;
|
this.knEmployee = knEmployee;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getMailAddress() {
|
public String getMailAddress() {
|
||||||
return mailAddress;
|
return mailAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMailAddress(String mailAddress) {
|
public void setMailAddress(String mailAddress) {
|
||||||
this.mailAddress = mailAddress;
|
this.mailAddress = mailAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getPassword() {
|
public String getPassword() {
|
||||||
return password;
|
return password;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPassword(String password) {
|
public void setPassword(String password) {
|
||||||
this.password = password;
|
this.password = password;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getIdDepartment() {
|
||||||
|
return idDepartment;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIdDepartment(String idDepartment) {
|
||||||
|
this.idDepartment = idDepartment;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getEmpCount() {
|
||||||
|
return empCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
|
||||||
public String getIdDepartment() {
|
|
||||||
|
|
||||||
return idDepartment;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void setIdDepartment(String idDepartment) {
|
|
||||||
this.idDepartment = idDepartment;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
return this.getIdEmployee()+"\t"
|
||||||
|
+this.getNmEmployee()+"\t"
|
||||||
|
+this.getKnEmployee()+"\t"
|
||||||
|
+this.getMailAddress()+"\t"
|
||||||
|
+this.getPassword()+"\t"
|
||||||
|
+this.getIdDepartment();
|
||||||
|
|
||||||
public boolean isMatchId(String id) {
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (this.idEmployee != null && this.idEmployee.equals(id)) {
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void showInfo() {
|
|
||||||
System.out.println(this.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
public boolean isMatchId(String id) {
|
||||||
|
return id.equals(this.getIdEmployee()) ;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
}
|
||||||
public String toString(){
|
|
||||||
return(getIdEmployee() + "\t" + getNmEmployee() + "\t" + getKnEmployee() + "\t" + getMailAddress() + "\t" +getPassword() + "\t" +getIdDepartment()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
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++;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static int getEmpCount() {
|
|
||||||
return empCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toCSV() {
|
|
||||||
return getIdEmployee() + "," + getNmEmployee() + "," + getKnEmployee() + "," + getMailAddress() + "," + getPassword() + "," + getIdDepartment();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getPrimaryKeyValue(){
|
|
||||||
return this.idEmployee;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,56 +0,0 @@
|
|||||||
|
|
||||||
class Item {
|
|
||||||
|
|
||||||
|
|
||||||
private String name;
|
|
||||||
private int price;
|
|
||||||
private int stock;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void setName(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public int getPrice() {
|
|
||||||
return price;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void setPrice(int price) {
|
|
||||||
this.price = price;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public int getStock() {
|
|
||||||
return stock;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void setStock(int stock) {
|
|
||||||
this.stock = stock;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void sell(int amount) {
|
|
||||||
this.setStock(this.getStock() - amount);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return getName() + " " + getPrice() + "円 (残り" + getStock() + "個)";
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -4,70 +4,95 @@ public class Main {
|
|||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// TODO 自動生成されたメソッド・スタブ
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
BaseData[] employees = new BaseData[5];
|
|
||||||
|
|
||||||
|
|
||||||
employees[0] = new EmployeeData("10000", "山田龍也", "ヤマダタツヤ", "yamada@hoge.jp", "aaa", "10");
|
//====================設定====================
|
||||||
employees[1] = new EmployeeData("10001", "高橋準", "タカハシジュン", "jtaka@hoge.jp", "bbb", "10");
|
EmployeeData[] employees = new EmployeeData[5];
|
||||||
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");
|
|
||||||
|
|
||||||
for (int i = 0; i < employees.length; i++) {
|
// EmployeeData employee0 = new EmployeeData();
|
||||||
|
// employee0.setIdEmployee(""); // 社員IDが空文字のとき
|
||||||
//System.out.println(employees[i]);
|
// employee0.setNmEmployee(""); // 社員名が空文字のとき
|
||||||
|
|
||||||
}
|
EmployeeData employee1 = new EmployeeData("10000", "山田龍也", "ヤマダタツヤ", "yamada@hoge.jp", "aaa", "10");
|
||||||
|
// EmployeeData employee1 = new EmployeeData();
|
||||||
System.out.println("現在のデータ件数:"+EmployeeData.getEmpCount()+"件");
|
// employee1.setIdEmployee("10000");
|
||||||
|
// employee1.setNmEmployee("山田龍也");
|
||||||
|
// employee1.setKnEmployee("ヤマダタツヤ");
|
||||||
while (true) {
|
// employee1.setMailAddress("yamada@hoge.jp");
|
||||||
|
// employee1.setPassword("aaa");
|
||||||
|
// employee1.setIdDepartment("10");
|
||||||
|
employees[1-1] = employee1;
|
||||||
|
|
||||||
//Scannerを使って、
|
EmployeeData employee2 = new EmployeeData();
|
||||||
Scanner scanner = new Scanner(System.in);
|
employee2.setIdEmployee("10001");
|
||||||
//「検索したい社員IDを入力してください」と表示し
|
employee2.setNmEmployee("高橋準");
|
||||||
System.out.println("検索したい社員IDを入力してください(終了する場合は0)");
|
employee2.setKnEmployee("タカハシジュン");
|
||||||
//キーボード入力を受け取る
|
employee2.setMailAddress("jtaka@hoge.jp");
|
||||||
String idEmployee = scanner.next();
|
employee2.setPassword("bbb");
|
||||||
|
employee2.setIdDepartment("10");
|
||||||
|
employees[2-1] = employee2;
|
||||||
|
|
||||||
if ("0".equals(idEmployee)) {
|
EmployeeData employee3 = new EmployeeData();
|
||||||
System.out.println("システムを終了します");
|
employee3.setIdEmployee("10002");
|
||||||
break;
|
employee3.setNmEmployee("麻枝史明");
|
||||||
}
|
employee3.setKnEmployee("マエダフミアキ");
|
||||||
|
employee3.setMailAddress("fmak@hoge.jp");
|
||||||
|
employee3.setPassword("ccc");
|
||||||
|
employee3.setIdDepartment("11");
|
||||||
|
employees[3-1] = employee3;
|
||||||
|
|
||||||
|
EmployeeData employee4 = new EmployeeData();
|
||||||
|
employee4.setIdEmployee("10003");
|
||||||
|
employee4.setNmEmployee("丸戸章介");
|
||||||
|
employee4.setKnEmployee("マルトショウスケ");
|
||||||
|
employee4.setMailAddress("marusyo@hoge.jp");
|
||||||
|
employee4.setPassword("ddd");
|
||||||
|
employee4.setIdDepartment("12");
|
||||||
|
employees[4-1] = employee4;
|
||||||
|
|
||||||
|
EmployeeData employee5 = new EmployeeData();
|
||||||
|
employee5.setIdEmployee("10004");
|
||||||
|
employee5.setNmEmployee("三宅武");
|
||||||
|
employee5.setKnEmployee("ミヤケタケシ");
|
||||||
|
employee5.setMailAddress("miya@hoge.jp");
|
||||||
|
employee5.setPassword("eee");
|
||||||
|
employee5.setIdDepartment("13");
|
||||||
|
employees[5-1] = employee5;
|
||||||
|
|
||||||
|
|
||||||
|
//====================表示====================
|
||||||
|
System.out.println(EmployeeData.COMPANY_NAME);
|
||||||
|
for ( EmployeeData employee : employees ) {
|
||||||
|
System.out.println(employee);
|
||||||
|
}
|
||||||
|
System.out.println("現在の社員データ件数:"+EmployeeData.getEmpCount()+"件");
|
||||||
|
|
||||||
|
|
||||||
|
//====================検索====================
|
||||||
|
while (true) {
|
||||||
|
|
||||||
//employees配列をfor文で1件ずつ確認し
|
System.out.println("検索したい社員IDを入力してください(終了する場合は0)");
|
||||||
for(int i = 0; i < employees.length; i++) {
|
Scanner sc = new Scanner(System.in);
|
||||||
|
String id = sc.nextLine();
|
||||||
|
|
||||||
|
|
||||||
if (((EmployeeData) employees[i]).isMatchId(idEmployee)) {
|
|
||||||
//一致する社員が見つかったら、その社員のshowInfoメソッドを呼び出す
|
|
||||||
((EmployeeData) employees[i]).showInfo();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
//
|
|
||||||
System.out.println("検索したいIDが見つかりませんでした");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
if ( id.equals("0") ) {
|
||||||
|
System.out.println("システムを終了します");
|
||||||
|
break;
|
||||||
//System.out.println(employees[0].toCSV());
|
}
|
||||||
//System.out.println(employees[0].getPrimaryKeyValue());
|
|
||||||
|
boolean matchId = false;
|
||||||
}
|
for ( EmployeeData employee : employees ) {
|
||||||
|
if ( employee.isMatchId(id) ) {
|
||||||
|
matchId = true;
|
||||||
|
System.out.println(employee);;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( matchId==false ) {
|
||||||
|
System.out.println("該当する社員が見つかりませんでした");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,30 +0,0 @@
|
|||||||
|
|
||||||
public class Student {
|
|
||||||
|
|
||||||
int studentId;
|
|
||||||
String name;
|
|
||||||
|
|
||||||
|
|
||||||
public void printProfile() {
|
|
||||||
System.out.println("学籍番号:"+this.studentId+" 名前:"+this.name);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Student(int StudentId,String name) {
|
|
||||||
|
|
||||||
this.studentId = StudentId;
|
|
||||||
this.name = name;
|
|
||||||
|
|
||||||
studentCount++;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public int getStudentCount() {
|
|
||||||
return studentCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int studentCount = 0;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user