This commit is contained in:
2026-10-19 14:15:21 +09:00
parent d656d3c5a8
commit 24aa555e45
8 changed files with 243 additions and 71 deletions

View File

@@ -4,14 +4,25 @@ 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);
}
}

View File

@@ -3,11 +3,17 @@ public class BasicCheck2 {
public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ
Student student = new Student();
student.studentId = 1;
student.name = "鈴木一郎";
student.printProfile();
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() + "人");
}
}

View File

@@ -6,28 +6,29 @@ public class BasicCheck3 {
Item[] items = new Item[3];
items[0] = new Item();
items[0].name = "ノート";
items[0].price = 120;
items[0].stock = 50;
items[0].setName("ノート");
items[0].setPrice(120);
items[0].setStock(50);
items[1] = new Item();
items[1].name = "消しゴム";
items[1] .price = 80;
items[1].stock = 30;
items[1].setName("消しゴム");
items[1].setPrice(80);
items[1].setStock(30);
items[2] = new Item();
items[2].name = "鉛筆";
items[2].price = 60;
items[2].stock = 100;
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].name + " 価格:" + items[i].price + "円 在庫:" + items[i].stock );
System.out.println(items[i]);
}
}

View File

@@ -3,4 +3,16 @@ 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;
}
}

View File

@@ -1,16 +1,126 @@
public class EmployeeData {
String idEmployee;
String nmEmployee;
String knEmployee;
String mailAddress;
String password;
String idDepartment;
private String idEmployee;
private String nmEmployee;
private String knEmployee;
private String mailAddress;
private String password;
private String idDepartment;
public void showInfo(){
System.out.println(this.idEmployee + "\t" + this.nmEmployee + "\t" + this.knEmployee + "\t" + "\t" + this.mailAddress + "\t" + this.password + "\t" + this.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;
}
@Override
public String toString(){
return(getIdEmployee() + "\t" + getNmEmployee() + "\t" + getKnEmployee() + "\t" + getMailAddress() + "\t" +getPassword() + "\t" +getIdDepartment()
);
}
public EmployeeData() {
}
public EmployeeData(String idEmployee, String nmEmployee, String knEmployee,String mailAddress, String password, String idDepartment) {
setIdEmployee(idEmployee);
setNmEmployee(nmEmployee);
setKnEmployee(knEmployee);
setMailAddress(mailAddress);
setPassword(password);
setIdDepartment(idDepartment);
}
}

View File

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

View File

@@ -5,50 +5,17 @@ public class Main {
// TODO 自動生成されたメソッド・スタブ
EmployeeData[] employees = new EmployeeData[5];
employees[0] = 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] = new EmployeeData();
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] = new EmployeeData();
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] = new EmployeeData();
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] = new EmployeeData();
employees[4].idEmployee = "10004";
employees[4].nmEmployee = "三宅武";
employees[4].knEmployee = "ミヤケタケシ";
employees[4].mailAddress = "miya@hoge.jp";
employees[4].password = "eee";
employees[4].idDepartment = "13";
employees[0] = new EmployeeData("10000", "山田龍也", "ヤマダタツヤ", "yamada@hoge.jp", "aaa", "10");
employees[1] = new EmployeeData("10001", "高橋準", "タカハシジュン", "jtaka@hoge.jp", "bbb", "10");
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++) {
employees[i].showInfo();
System.out.println(employees[i]);
}
}
}
}
}
}

View File

@@ -8,4 +8,23 @@ public class Student {
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;
}