C#练习--库存管理

    xiaoxiao2021-12-12  5

    class Storage { Goods o = new Goods(); Goods [] g=new Goods[3]; public void Initial() { g[0]=new Goods(); g[0].Name = "杯子"; g[0].Where = "第一仓库第一排"; g[0].Money = 10.1; g[0].Manyidu = 90; g[1] = new Goods(); g[1].Name = "花瓶"; g[1].Where = "第二仓库第二排"; g[1].Money = 12.1; g[1].Manyidu = 95; g[2] = new Goods(); g[2].Name = "热水器"; g[2].Where = "第三仓库第三排"; g[2].Money = 11.1; g[2].Manyidu = 97; foreach (Goods item in g) { string a = string.Format("货品名称:{0}", item.Name, item.Name, item.Name); Console.WriteLine(a); } } public void ShowMenu() { bool con=false; do{ Console.WriteLine("==========================欢迎使用库存管理系统=========================="); Console.WriteLine("1:根据货品名称获取货品位置 2:取得客户满意度最高的货品 3:退出"); Console.WriteLine("请选择:"); int x = int.Parse(Console.ReadLine()); if(x==1){ if (GetGoodsPlace() == false) Console.WriteLine("您输入的货品名称不正确!"); con=true; }else if(x==2){ GetMaxPleased(); con=true; } else if (x == 3) { Console.WriteLine("谢谢使用!"); con = false; }else{ Console.WriteLine("输入e停止购物,输入其他任意键继续购物!"); con=true; } }while(con); } public void ShowGoods() { Console.WriteLine("----------------------------"); foreach (Goods iteming in g) { Console.WriteLine("货品名称:"+iteming.Name); } Console.WriteLine("-----------------------------"); } public bool GetGoodsPlace(){ bool ton = false; Console.WriteLine("请输入商品名称:"); string goods = Console.ReadLine(); foreach (Goods ite in g) { if(ite.Name.Equals(goods)){ ton = true; Console.WriteLine(ite.Where); } } return ton; } public void GetMaxPleased() { o = GetPleased(); string goodsname = string.Format("客户满意度最高的货品:{0}摆放在:{1}满意度:{2}价格:{3}",o.Name,o.Where,o.Manyidu,o.Money); Console.WriteLine(goodsname); } private Goods GetPleased() { o.Manyidu = 0; foreach (Goods itt in g) { if(itt.Manyidu>o.Manyidu){ o.Manyidu = itt.Manyidu; o.Name = itt.Name; o.Money = itt.Money; o.Where = itt.Where; } } return o; } class Goods { private string name; public string Name { get { return name; } set { name = value; } } private string where; public string Where { get { return where; } set { where = value; } } private double money; public double Money { get { return money; } set { money = value; } } private int manyidu; public int Manyidu { get { return manyidu; } set { manyidu = value; } } } static void Main(string[] args) { Storage s = new Storage(); s.Initial(); s.ShowMenu(); Console.ReadLine(); }
    转载请注明原文地址: https://ju.6miu.com/read-900168.html

    最新回复(0)