7 Commits

8 changed files with 150 additions and 2 deletions

View File

@@ -3,7 +3,13 @@ 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);
}
}

View File

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

View File

@@ -0,0 +1,26 @@
public class BasicCheck3 {
public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ
Item[] items = new Item[3];
for (int i = 0; i < items.length; i++) {
items[i] = 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;
for (Item i : items) {
i.sell(5);
System.out.println(i.name + " " + i.price + "円 残り" + i.stock + "個 合計金額" + i.totalPrice() + "円");
}
}
}

View File

@@ -1,4 +1,6 @@
public class Book {
String title;
String author;
int price;
}

View File

@@ -0,0 +1,15 @@
public class EmployeeData {
String idEmployee;
String nmEmployee;
String knEmployee;
String mailAddress;
String password;
String idDepartment;
void showInfo() {
System.out.println(this.idEmployee + "\t" + this.nmEmployee
+ "\t" + this.knEmployee + "\t" + this.mailAddress
+ "\t" + this.password + "\t" + this.idDepartment);
}
}

14
em-oop/src/Item.java Normal file
View File

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

64
em-oop/src/Main.java Normal file
View File

@@ -0,0 +1,64 @@
public class Main {
public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ
EmployeeData employee = new EmployeeData();
employee.idEmployee = "10000";
employee.nmEmployee = "山田龍也";
employee.knEmployee = "ヤマダタツヤ";
employee.mailAddress = "yamada@hoge.jp";
employee.password = "aaa";
employee.idDepartment = "10";
employee.showInfo();
EmployeeData[] employees = new EmployeeData[5];
for (int i = 0; i < employees.length; i++) {
employees[i] = 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";
for (EmployeeData e : employees) {
e.showInfo();
}
}
}

9
em-oop/src/Student.java Normal file
View File

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