zhongdazui
zhongdazui
2015-08-29 16:44

用C#简单模拟超市收银碰到的问题

  • c#

class SuperMarket
{
WareHouse CangKu = new WareHouse();
//CangKu.GoodsIn("DreamCar", 100);这么写会报错
public SuperMarket()
{
CangKu.GoodsIn("DreamCar", 100);
CangKu.GoodsIn("Apple", 800);
CangKu.GoodsIn("Book", 997);
CangKu.GoodsIn("Pencil", 68);
}
}

    ——————————————分割线—————————————————
    class WareHouse
{
    List<List<Commodity>> storeroom = new List<List<Commodity>>();
    public WareHouse()
    {
        storeroom.Add(new List<Commodity>());
        storeroom.Add(new List<Commodity>());
        storeroom.Add(new List<Commodity>());
        storeroom.Add(new List<Commodity>());
    }
    public void GoodsIn(string type, int count)
    {
        for (int i = 0; i < count; i++)
        {
            switch (type)
            {
                case "DreamCar": storeroom[0].Add(new DreamCar("DreamCar", 180000, Guid.NewGuid().ToString())); break;
                case "Apple": storeroom[1].Add(new Apple("嘎?果", 3, Guid.NewGuid().ToString())); break;
                case "Book": storeroom[2].Add(new Book("心灵鸭汤读本", 14, Guid.NewGuid().ToString())); break;
                case "Pencil": storeroom[3].Add(new Pencil("小嘴牌铅笔", 0.9, Guid.NewGuid().ToString())); break;
            }
        }
    }
        }   ![图片说明](https://img-ask.csdn.net/upload/201508/30/1440866253_103476.png)

        想简单模拟超市收银,写好WareHouse类,然后在SuperMarket中创建CangKu的时候,想添加商品进去,出现了图示情况。我初学,实在太菜,请大神指导,3Q。
  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

3条回答