Counter Stock メソッドを呼び出すと、次のようになります。
FoodProducts FoodProd1 = new FoodProducts("FP001", "Meat", 15.99, 200, 100, "Australia");
FoodProducts FoodProd2 = new FoodProducts("FP002", "Bread", 2.99, 150, 50, "Italy");
Console.WriteLine("This is the Total Stock For the Store: {0}", CounterStock(ProductList)); **//Not Displaying the Total Stock of All items it equals to 0**
List<Products> ProductList = new List<Products>();
static int CounterStock(List<Products> ProductList)
{
int CounterStoreStock = 0;
foreach (Products Count in ProductList)
{
CounterStoreStock += Count.StockCount++;
}
return CounterStoreStock;
}
継承を使用しています
class Products
{
string id;
string name;
double price;
int soldCount;
int stockCount;
public Products(string id, string name, double price, int soldCount, int stockCount)
{
this.id = id;
this.name = name;
this.price = price;
this.soldCount = soldCount;
this.stockCount = stockCount;
}
public string ID
{
get{return id;}
}
public string Name
{
get { return name; }
set {name = value;}
}
public double Price
{
get {return price;}
set {price = value;}
}
public int SoldCount
{
get {return soldCount;}
set { soldCount = value; }
}
public int StockCount
{
get {return stockCount;}
set {stockCount = value;}
}
public virtual double Tax()
{
/*
double tax;
const double Rate = 0.05;
tax = Price * Rate;
*/
return 0;
}
// Print Method for the Products Class
public virtual void Print()
{
Console.WriteLine("Product ID: {0}", this.id);
Console.WriteLine("Product Name: {0}", this.name);
Console.WriteLine("Prodcut Price: {0}", this.price);
Console.WriteLine("Sold Counter: {0}", this.soldCount);
Console.WriteLine("Stock Count: {0}", this.stockCount);
Console.WriteLine();
//Console.WriteLine(Tax());
}
}
これが製品クラスです。さらに情報が必要な場合は、それを掲載してください。ありがとう、すべての在庫の合計を計算しようとすると、現在、出力は常に 0 しか表示されないため、何が間違っているのかよくわかりません。
class FoodProducts : Products
{
private string origin;
public FoodProducts(string id, string name, double price, int soldCount, int stockCount, string origin)
: base(id, name, price, soldCount, stockCount)
{
this.origin = origin;
}
private string Origin
{
get { return origin; }
set { origin = value; }
}
public override void Print()
{
base.Print();
Console.WriteLine("Origin: {0}", this.Origin);
Console.WriteLine("------------------");
}