10/14 開発課題

This commit is contained in:
2026-10-14 16:37:20 +09:00
parent 79fb30d941
commit 2b4e19fae2
8 changed files with 239 additions and 0 deletions

17
BasicCheck1.java Normal file
View File

@@ -0,0 +1,17 @@
package misson1014;
public class BasicCheck1 {
public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ
Book book = new Book();
book.title = "吾輩は猫である";
book.author = "夏目漱石";
book.price = 800;
System.out.println(book.title);
System.out.println(book.author);
System.out.println(book.price);
}
}

14
BasicCheck2.java Normal file
View File

@@ -0,0 +1,14 @@
package misson1014;
public class BasicCheck2 {
public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ
Student student = new Student();
student.studentId = 1;
student.name = "鈴木一郎";
student.printProfile();
}
}

48
BasicCheck3.java Normal file
View File

@@ -0,0 +1,48 @@
package misson1014;
public class BasicCheck3 {
public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ
Item[] items = new Item[3];
items[0] = new Item();
items[1] = new Item();
items[2] = new Item();
items[0].name = "ノート";
items[0].price = 120;
items[0].stock = 50;
items[1].name = "消しゴム";
items[1].price = 80;
items[1].stock = 30;
items[2].name = "鉛筆";
items[2].price = 60;
items[2].stock = 100;
// 5個販売
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].name + " "
+ items[i].price + "円 "
+ "残り" + items[i].stock + "個"
);
}
// 合計金額を計算
int total = 0;
for (int i = 0; i < items.length; i++) {
total += items[i].totalPrice();
}
System.out.println("合計金額:" + total + "円");
}
}

7
Book.java Normal file
View File

@@ -0,0 +1,7 @@
package misson1014;
public class Book {
String title;
String author;
int price;
}

39
EmployeeData.java Normal file
View File

@@ -0,0 +1,39 @@
package misson1014;
public class EmployeeData {
//社員ID
String idEmployee;
//社員名
String nmEmployee;
//カナ
String knEmployee;
//メールアドレス
String mailAddress;
//PW
String password;
//部署ID
String idDepartment;
//まとめて表示
void showInfo() {
System.out.println(
this.idEmployee + "\t"
+ this.nmEmployee + "\t"
+ this.knEmployee + "\t"
+ this.mailAddress + "\t"
+ this.password + "\t"
+ this.idDepartment);
}
//IDチェック
boolean isMatchId(String id) {
if (this.idEmployee.equals(id)) {
return true;
} else {
return false;
}
}
}

15
Item.java Normal file
View File

@@ -0,0 +1,15 @@
package misson1014;
public class Item {
String name;
int price;
int stock;
void sell(int amount) {
this.stock = this.stock - amount;
}
int totalPrice() {
return this.price * this.stock;
}
}

89
Main.java Normal file
View File

@@ -0,0 +1,89 @@
package misson1014;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ
// 5人の配列を作成
EmployeeData[] employees = new EmployeeData[5];
// インスタンス生成
employees[0] = new EmployeeData();
employees[1] = new EmployeeData();
employees[2] = new EmployeeData();
employees[3] = new EmployeeData();
employees[4] = new EmployeeData();
employees[0].idEmployee = "10000";
employees[0].nmEmployee = "山田龍也";
employees[0].knEmployee = "ヤマダタツヤ";
employees[0].mailAddress = "yamada@hoge.jp";
employees[0].password = "aaa";
employees[0].idDepartment = "10";
employees[1].idEmployee = "10001";
employees[1].nmEmployee = "高橋準";
employees[1].knEmployee = "タカハシジュン";
employees[1].mailAddress = "jtaka@hoge.jp";
employees[1].password = "bbb";
employees[1].idDepartment = "10";
employees[2].idEmployee = "10002";
employees[2].nmEmployee = "麻枝史明";
employees[2].knEmployee = "マエダフミアキ";
employees[2].mailAddress = "fmak@hoge.jp";
employees[2].password = "ccc";
employees[2].idDepartment = "11";
employees[3].idEmployee = "10003";
employees[3].nmEmployee = "丸戸章介";
employees[3].knEmployee = "マルトショウスケ";
employees[3].mailAddress = "marusyo@hoge.jp";
employees[3].password = "ddd";
employees[3].idDepartment = "12";
employees[4].idEmployee = "10004";
employees[4].nmEmployee = "三宅武";
employees[4].knEmployee = "ミヤケタケシ";
employees[4].mailAddress = "miya@hoge.jp";
employees[4].password = "eee";
employees[4].idDepartment = "13";
Scanner scanner = new Scanner(System.in);
//0までループ
while (true) {
//ID検索
System.out.println("検索したい社員IDを入力してください(終了する場合は0)");
String search = scanner.nextLine();
//0なら終了
if (search.equals("0")) {
System.out.println("システムを終了します");
break;
}
//見つかったかどうか
boolean found = false;
//内部検索
for (int i = 0; i < employees.length; i++) {
// ID判定
if (employees[i].isMatchId(search)) {
employees[i].showInfo();
found = true;
break;
}
}
// 見つからなかった
if (!found) {
System.out.println("該当する社員が見つかりませんでした");
}
}
scanner.close();
}
}

10
Student.java Normal file
View File

@@ -0,0 +1,10 @@
package misson1014;
public class Student {
int studentId;
String name;
void printProfile() {
System.out.println("学籍番号:" + this.studentId + " 名前:" + this.name);
}
}