Compare commits
4 Commits
m-endo
...
769fb977ca
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
769fb977ca | ||
|
|
04da447bfe | ||
|
|
25802b8380 | ||
|
|
be15630c5b |
@@ -3,7 +3,13 @@ public class BasicCheck1 {
|
|||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// TODO 自動生成されたメソッド・スタブ
|
// 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
12
em-oop/src/BasicCheck2.java
Normal file
12
em-oop/src/BasicCheck2.java
Normal 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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
26
em-oop/src/BasicCheck3.java
Normal file
26
em-oop/src/BasicCheck3.java
Normal 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() + "円");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,4 +1,6 @@
|
|||||||
|
|
||||||
public class Book {
|
public class Book {
|
||||||
|
String title;
|
||||||
|
String author;
|
||||||
|
int price;
|
||||||
}
|
}
|
||||||
|
|||||||
14
em-oop/src/Item.java
Normal file
14
em-oop/src/Item.java
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
9
em-oop/src/Student.java
Normal file
9
em-oop/src/Student.java
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
|
||||||
|
public class Student {
|
||||||
|
int studentId;
|
||||||
|
String name;
|
||||||
|
|
||||||
|
void printProfile() {
|
||||||
|
System.out.println("学籍番号:" + this.studentId + " 名前:" + this.name);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user