2段階目終わりました
This commit is contained in:
@@ -6,13 +6,9 @@ public class BasicCheck1 {
|
||||
Book book1 = new Book();
|
||||
Book book2 = new Book("銀河鉄道の夜", "宮沢賢治", 500);
|
||||
|
||||
|
||||
System.out.println(book1.title + "\n" + book1.author + "\n" + book1.price);
|
||||
System.out.println(book2.title + "\n" + book2.author + "\n" + book2.price);
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,23 +6,23 @@ public class BasicCheck3 {
|
||||
items[1] = new Item();
|
||||
items[2] = new Item();
|
||||
|
||||
items[0].name = "ノート";
|
||||
items[1].name = "消しゴム";
|
||||
items[2].name = "鉛筆";
|
||||
items[0].setName("ノート");
|
||||
items[1].setName("消しゴム");
|
||||
items[2].setName("鉛筆");
|
||||
|
||||
items[0].price = 120;
|
||||
items[1].price = 80;
|
||||
items[2].price = 60;
|
||||
items[0].setPrice(120);
|
||||
items[1].setPrice(80);
|
||||
items[2].setPrice(60);
|
||||
|
||||
items[0].stock = 50;
|
||||
items[1].stock = 30;
|
||||
items[2].stock = 100;
|
||||
items[0].setStock(50);
|
||||
items[1].setStock(30);
|
||||
items[2].setStock(100);
|
||||
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
items[i].sell(5);
|
||||
System.out.println(items[i].name + " " + items[i].price + "円 残り" + items[i].stock + "個 ");
|
||||
System.out.println("合計金額 " + items[i].totalPrice() + "円");
|
||||
System.out.println();
|
||||
System.out.println(items[i].getName() + " " + items[i].getPrice() + "円 (残り" + items[i].getStock() + "個) ");
|
||||
// System.out.println("合計金額 " + items[i].totalPrice() + "円");
|
||||
// System.out.println();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
|
||||
public class Book {
|
||||
|
||||
|
||||
String title;
|
||||
String author ;
|
||||
String author;
|
||||
int price;
|
||||
|
||||
public Book() {
|
||||
@@ -13,13 +12,11 @@ public class Book {
|
||||
|
||||
}
|
||||
|
||||
public Book(String title, String author, int price){
|
||||
public Book(String title, String author, int price) {
|
||||
this.title = title;
|
||||
this.author = author;
|
||||
this.price = price;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
|
||||
public class Item {
|
||||
String name;
|
||||
int price;
|
||||
int stock;
|
||||
private String name;
|
||||
private int price;
|
||||
private int stock;
|
||||
|
||||
public void sell(int amount) {
|
||||
this.stock = this.stock - amount;
|
||||
this.setStock(this.getStock() - amount);
|
||||
}
|
||||
|
||||
public int totalPrice() {
|
||||
@@ -12,5 +13,33 @@ public class Item {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return (getName() + " " + getPrice() + "円 (残り" + getStock() + "個");
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user