2日目 段階2 小澤

This commit is contained in:
2026-09-15 14:02:17 +09:00
parent 992bd30434
commit a3ddbaed43
2 changed files with 43 additions and 15 deletions

View File

@@ -1,15 +1,43 @@
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() {
return this.price*this.stock;
}
@Override
public String toString() {
return getName()+" "+getPrice()+"円(残り"+getStock()+"個)";
}
public String getName() {
return this.name;
}
public void setName(String name) {
this.name=name;
}
public int getPrice() {
return this.price;
}
public void setPrice(int price) {
this.price=price;
}
public int getStock() {
return this.stock;
}
public void setStock(int stock) {
this.stock=stock;
}
}