私は独学で Java を勉強しています。このクラスは Product と呼ばれ、小さな会社が販売する製品を表すために使用されます。
各製品に関する次の情報を格納できる必要があります。クラスには次のメソッドが必要です。
- コンストラクター
- ストア内のアイテムのユニットを返すメソッド
- 店舗への配送方法(この商品の個数を増やします)
- 店舗からの退出方法(本商品の数量を減らします)
いずれかの方法で注文ポイントの下に格納されているアイテムが変更された場合、メッセージが出力される必要があることに注意してください。また、アイテムの数がマイナスになることもありません。
方法に問題があります。私のコードを見て、ヒントを教えてください。私はすべての応答に感謝します。ありがとうございました。
これが私のプログラムです:
public class Product {
private int productNumber;
private String productName;
private float price;
private int orderPoint;
private int unitsInStore;
private String proDescription;
public Product(int num, String name, float price, int order, int units, String description){
this.productNumber = num;
this.productName = name;
this.price = price;
this.orderPoint = order;
this.unitsInStore = units;
this.proDescription = description;
}
public int getProductNumber() {
return productNumber;
}
public void setProductNumber(int productNumber) {
this.productNumber = productNumber;
}
public String getProductName() {
return productName;
}
public void setProductName(String productName) {
this.productName = productName;
}
public float getPrice() {
return price;
}
public void setPrice(float price) {
this.price = price;
}
public int getOrderPoint() {
return orderPoint;
}
public void setOrderPoint(int orderPoint) {
this.orderPoint = orderPoint;
}
// a method returns the units in store
public int getUnitsInStore() {
return unitsInStore;
}
public void setUnitsInStore(int unitsInStore) {
this.unitsInStore = unitsInStore;
}
public String getProDescription() {
return proDescription;
}
public void setProDescription(String proDescription) {
this.proDescription = proDescription;
}
public int deliveranceToStore(int store){
unitsInStore = unitsInStore + store;
return unitsInStore ++ ;
}
public int withdrawal(int store){
unitsInStore = store - unitsInStore;
return unitsInStore --;
}
}