2日目段階2~4です

This commit is contained in:
2026-09-18 11:34:35 +09:00
parent 90ac263e9c
commit b6f3df93ed
6 changed files with 222 additions and 92 deletions

View File

@@ -3,12 +3,24 @@ public class BasicCheck2 {
public static void main(String[] args) { public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ // TODO 自動生成されたメソッド・スタブ
Student student = new Student (); Student student1 = new Student(1, "鈴木一郎");
student.studentId = 1; // student1.studentId = 1;
student.name = "鈴木一郎"; // student1.name = "鈴木一郎";
student1.printProfile();
Student student2 = new Student(2, "田中花子");
student2.printProfile();
Student student3 = new Student(3, "佐藤次郎");
student3.printProfile();
Student.getStudentCount();{
System.out.println("現在の生徒数:" + Student.studentCount + "人");
}
student.printProfile();
} }
} }

View File

@@ -6,34 +6,46 @@ public class BasicCheck3 {
Item[] items = new Item[3]; Item[] items = new Item[3];
Item item0 = new Item();
Item item1 = new Item(); Item item1 = new Item();
item1.name = "ノート";
item1.price = 120;
item1.stock = 50;
Item item2 = new Item(); Item item2 = new Item();
item2.name = "消しゴム"; items[0] = item0;
item2.price = 80; items[1] = item1;
item2.stock = 30; items[2] = item2;
Item item3 = new Item(); item0.setName("ノート");
item0.setPrice(120);
item0.setStock(50);
item3.name = "鉛筆"; item1.setName("消しゴム");
item3.price = 60; item1.setPrice(80);
item3.stock = 100; item1.setStock(30);
items[0] = item1; item2.setName("鉛筆");
items[1] = item2; item2.setPrice(60);
items[2] = item3; item2.setStock(100);
// item1.setName = "ノート";
// item1.price = 120;
// item1.stock = 50;
//
// Item item2 = new Item();
//
// item2.name = "消しゴム";
// item2.price = 80;
// item2.stock = 30;
//
// Item item3 = new Item();
//
// item3.name = "鉛筆";
// item3.price = 60;
// item3.stock = 100;
for (int i = 0; i < items.length; i++) { for (int i = 0; i < items.length; i++) {
items[i].sell(5); items[i].sell(5);
System.out.println(items[i].name +" " + items[i].price +"円 " + "残り" +items[i].stock +"個"); System.out.println(items[i]);
} }

View File

@@ -1,14 +1,72 @@
public class EmployeeData { public class EmployeeData {
String idEmployee; private String idEmployee;
String nmEmployee; private String nmEmployee;
String knEmployee; private String knEmployee;
String mailAddress; private String mailAddress;
String password; private String password;
String idDepartment; private String idDepartment;
EmployeeData(String idEmployee, String nmEmployee, String knEmployee, String mailAddress, String password,
String idDepartment) {
this.idEmployee = idEmployee;
this.nmEmployee = nmEmployee;
this.knEmployee = knEmployee;
this.mailAddress = mailAddress;
this.password = password;
this.idDepartment = idDepartment;
}
public String getIdEmployee() {
return idEmployee;
}
public void setIdEmployee(String idEmployee) {
this.idEmployee = idEmployee;
}
public String getNmEmployee() {
return nmEmployee;
}
public void setNmEmployee(String nmEmployee) {
this.nmEmployee = nmEmployee;
}
public String getKnEmployee() {
return knEmployee;
}
public void setKnEmployee(String knEmployee) {
this.knEmployee = knEmployee;
}
public String getMailAddress() {
return mailAddress;
}
public void setMailAddress(String mailAddress) {
this.mailAddress = mailAddress;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getIdDepartment() {
return idDepartment;
}
public void setIdDepartment(String idDepartment) {
this.idDepartment = idDepartment;
}
void showInfo() { void showInfo() {
System.out.println(this.idEmployee + "\t" + this.nmEmployee + "\t" + this.knEmployee + "\t" + this.mailAddress System.out.println(getIdEmployee() + "\t" + getNmEmployee() + "\t" + getKnEmployee() + "\t" + getMailAddress()
+ "\t" + this.password + "\t" + this.idDepartment); + "\t" + getPassword() + "\t" + getIdDepartment());
} }
} }

View File

@@ -1,10 +1,44 @@
public class Item { public class Item {
String name; private String name;
int price; private int price;
int stock; private int stock;
void sell(int amount) { // void sell(int amount) {
this.stock = this.stock - amount; // this.stock = this.stock - amount;
public void sell(int amount) {
setStock(this.getStock() - amount);
} }
@Override
public String toString() {
String output = getName() + " " + getPrice() + "円 (残り" + getStock() + "個)";
return output;
}
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;
}
} }

View File

@@ -6,50 +6,50 @@ public class Main {
EmployeeData[] employees = new EmployeeData[5]; EmployeeData[] employees = new EmployeeData[5];
EmployeeData employee = new EmployeeData(); EmployeeData employee = new EmployeeData("10001","山田龍也","ヤマダタツヤ","yamada@hoge.jp","aaa","10");
employee.idEmployee = "10001"; // employee.idEmployee = "10001";
employee.nmEmployee = "山田龍也"; // employee.nmEmployee = "山田龍也";
employee.knEmployee = "ヤマダタツヤ"; // employee.knEmployee = "ヤマダタツヤ";
employee.mailAddress = "yamada@hoge.jp"; // employee.mailAddress = "yamada@hoge.jp";
employee.password = "aaa"; // employee.password = "aaa";
employee.idDepartment = "10"; // employee.idDepartment = "10";
EmployeeData employee1 = new EmployeeData(); EmployeeData employee1 = new EmployeeData("10002","高橋準","タカハシジュン","jtaka@hoge.jp","bbb","10");
employee1.idEmployee = "10002"; // employee1.idEmployee = "10002";
employee1.nmEmployee = "高橋準"; // employee1.nmEmployee = "高橋準";
employee1.knEmployee = "タカハシジュン"; // employee1.knEmployee = "タカハシジュン";
employee1.mailAddress = "jtaka@hoge.jp"; // employee1.mailAddress = "jtaka@hoge.jp";
employee1.password = "bbb"; // employee1.password = "bbb";
employee1.idDepartment = "10"; // employee1.idDepartment = "10";
EmployeeData employee2 = new EmployeeData(); EmployeeData employee2 = new EmployeeData("10003", "麻枝史明","マエダフミアキ","fmak@hoge.jp","ccc","11");
employee2.idEmployee = "10003"; // employee2.idEmployee = "10003";
employee2.nmEmployee = "麻枝史明"; // employee2.nmEmployee = "麻枝史明";
employee2.knEmployee = "マエダフミアキ"; // employee2.knEmployee = "マエダフミアキ";
employee2.mailAddress = "fmak@hoge.jp"; // employee2.mailAddress = "fmak@hoge.jp";
employee2.password = "ccc"; // employee2.password = "ccc";
employee2.idDepartment = "11"; // employee2.idDepartment = "11";
EmployeeData employee3 = new EmployeeData(); EmployeeData employee3 = new EmployeeData("10004","丸戸章介", "マルトショウスケ","marusyo@hoge.jp","ddd","12");
employee3.idEmployee = "10004"; // employee3.idEmployee = "10004";
employee3.nmEmployee = "丸戸章介"; // employee3.nmEmployee = "丸戸章介";
employee3.knEmployee = "マルトショウスケ"; // employee3.knEmployee = "マルトショウスケ";
employee3.mailAddress = "marusyo@hoge.jp"; // employee3.mailAddress = "marusyo@hoge.jp";
employee3.password = "ddd"; // employee3.password = "ddd";
employee3.idDepartment = "12"; // employee3.idDepartment = "12";
EmployeeData employee4 = new EmployeeData(); EmployeeData employee4 = new EmployeeData("10005","三宅武","ミヤケタケシ","miya@hoge.jp,eee","eee","13");
employee4.idEmployee = "10005"; // employee4.idEmployee = "10005";
employee4.nmEmployee = "三宅武"; // employee4.nmEmployee = "三宅武";
employee4.knEmployee = "ミヤケタケシ"; // employee4.knEmployee = "ミヤケタケシ";
employee4.mailAddress = "miya@hoge.jp,eee"; // employee4.mailAddress = "miya@hoge.jp,eee";
employee4.password = "eee"; // employee4.password = "eee";
employee4.idDepartment = "13"; // employee4.idDepartment = "13";
employees[0] = employee; employees[0] = employee;
employees[1] = employee1; employees[1] = employee1;

View File

@@ -2,10 +2,24 @@
public class Student { public class Student {
int studentId; int studentId;
String name; String name;
static int studentCount = 0;
{
studentCount++;
}
Student(int studentId, String name) {
this.studentId = studentId;
this.name = name;
}
public static int getStudentCount() {
return studentCount;
}
void printProfile() { void printProfile() {
System.out.println("学籍番号:" + this.studentId + " 名前:" + this.name); System.out.println("学籍番号:" + this.studentId + " 名前:" + this.name);
} }
} }