栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > .Net

C#实现--超市管理系统

.Net 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

C#实现--超市管理系统

侵删~非原创,自己码的。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SupermarketManagermentSystem
{
    class Supermarket
    {
        //为超市创建仓库对象
        CangKu ck = new CangKu();
        /// 
        /// 在仓库中存入电脑手机酱油香蕉各1000
        /// 
       public  Supermarket()
        {
            ck.CunProducter("Acer", 1000);
            ck.CunProducter("Samsung", 1000);
            ck.CunProducter("JiangOil", 1000);
            ck.CunProducter("Banana", 1000);
        }
        public void AskBuy()
        {
            Console.WriteLine("欢迎光临,您需要什么?");
            Console.WriteLine("我们这有电脑,手机,酱油和香蕉。");
            string strtype = Console.ReadLine();
            Console.WriteLine("您需要多少?");
            int count =int.Parse( Console.ReadLine());
            //到仓库中取货
           ProductBase[] products= ck.Quproducter(strtype, count);
            //计算价钱
            double  money = this.GetMoney(products);
            Console.WriteLine("您需要支付"+ money+"元钱");
            Console.WriteLine("请输入您的打折方式:1--不打折  2--九折  3--八点五折  4--满300送50");
            int discount = int.Parse(Console.ReadLine());
            switch (discount)
            {
                case 1:
                    Discount1 discount1 = new Discount1();
                    Console.WriteLine("打折后您需要支付" + discount1.GetTotalMoney(money) + "元钱");
                    break;
                case 2:
                    Discount2 discount2 = new Discount2();
                    Console.WriteLine("打折后您需要支付" + discount2.GetTotalMoney(money) + "元钱");
                    break;
                default:
                    break;
            }

        }
        /// 
        /// 计算顾客购买商品的价钱
        /// 
        /// 
        public double GetMoney(ProductBase[] products)
        {
            double money = 0;
            for(int i=0;i
                money += products[i].price;
            }
            return money;
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SupermarketManagermentSystem
{
     class Samsung:ProductBase
    {
        public Samsung(double _price, string _name, string _id)
            :base(_price,_name,_id)
        {         
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SupermarketManagermentSystem
{
    class Program
    {
        static void Main(string[] args)
        {
            Supermarket supermarket = new Supermarket();
            supermarket.AskBuy();
            Console.ReadKey();
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SupermarketManagermentSystem
{
    class ProductBase
    {
        /// 
        /// 自动属性--价格
        /// 
         public double price
        {
            set;
            get;
        }
        /// 
        /// 自动属性--商品名称
        /// 
        public string name
        {
            set;
            get;
        }
        /// 
        /// 自动属性--编号
        /// 
        public string id
        {
            set;
            get;
        }
        /// 
        /// 构造函数,用于类的初始化
        /// 
        /// 
        /// 
        /// 
        public   ProductBase(double _price,string _name,string _id)
        {
            this.price = _price;
            this.name = _name;
            this.id = _id;
        }


    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SupermarketManagermentSystem
{
    class JiangOil:ProductBase
    {
        public JiangOil(double _price, string _name, string _id)
    : base(_price, _name, _id)
        {
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SupermarketManagermentSystem
{
    /// 
    /// 打折父类
    /// 
   abstract class DiscountBase
    {
        public abstract double GetTotalMoney(double money);

    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SupermarketManagermentSystem
{
    class Discount2:DiscountBase
    {
        public override double GetTotalMoney(double money)
        {
            double realmoney = 0;
            realmoney = 0.9*money;
            return realmoney;
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SupermarketManagermentSystem
{
    class Discount1:DiscountBase
    {
        public override double GetTotalMoney(double money)
        {
            double realmoney = 0;
            realmoney = money;
            return realmoney;
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SupermarketManagermentSystem
{
    class CangKu
    {
        //存储货物
       List< List> CKList = new List>();
        /// 
        /// 初始化函数中,将货架存入仓库中
        /// 其中:CKList[0]存储 Acer电脑
        ///           CKList[1]存储 Samsung手机
        ///           CKList[2]存储 酱油JiangOil
        ///           CKList[3]存储 香蕉Banana
        /// 
        public CangKu()
        {
            CKList.Add(new List());
            CKList.Add(new List());
            CKList.Add(new List());
            CKList.Add(new List());
        }
        /// 
        /// 往仓库中存放货物
        /// 
        public void CunProducter(string strtype,int count)
        {
            for(int i=0;i
                switch (strtype)
                {
                    case "Acer":
                        Console.WriteLine("往仓库中存放宏基电脑一台");
                        CKList[0].Add(new Acer(1000,"宏基电脑",Guid.NewGuid().ToString()));
                        break;
                    case "Samsung":
                        Console.WriteLine("往仓库中存放三星手机一部");
                        CKList[1].Add(new Acer(1500, "三星手机", Guid.NewGuid().ToString()));
                        break;
                    case "JiangOil":
                        Console.WriteLine("往仓库中存放酱油一瓶");
                        CKList[2].Add(new Acer(10, "酱油", Guid.NewGuid().ToString()));
                        break;
                    case "Banana":
                        Console.WriteLine("往仓库中存放香蕉一只");
                        CKList[3].Add(new Acer(5, "香蕉", Guid.NewGuid().ToString()));
                        break;
                    default:
                        break;
                }
            }
        }
        /// 
        /// 从仓库中取出货物
        /// 
        public ProductBase[] Quproducter(string strtype,int count)
        {
            ProductBase[] productBases = new ProductBase[count];
            for (int i = 0; i < count; i++)
            {
                switch (strtype)
                {
                    case "Acer":
                        Console.WriteLine("从仓库中取出宏基电脑一台");
                        productBases[i] = CKList[0][0];//读取一个Acer
                        CKList[0].RemoveAt(0);//在仓库中删除一个Acer
                        break;
                    case "Samsung":
                        Console.WriteLine("从仓库中取出三星手机一部");
                        productBases[i] = CKList[1][0];//读取一个Samsung
                        CKList[1].RemoveAt(0);//在仓库中删除一个Samsung
                        break;
                    case "JiangOil":
                        Console.WriteLine("从仓库中取出酱油一瓶");
                        productBases[i] = CKList[2][0];//读取一个JiangOil
                        CKList[2].RemoveAt(0);//在仓库中删除一个JiangOil
                        break;
                    case "Banana":
                        Console.WriteLine("从仓库中取出香蕉一只");
                        productBases[i] = CKList[3][0];//读取一个Banana
                        CKList[3].RemoveAt(0);//在仓库中删除一个Banana
                        break;
                    default:
                        break;
                }
            }
            return productBases;
        }
        /// 
        /// 显示超市仓库中的货物清单
        /// 
        public void ShowCKProduct()
        {
            foreach (var item in CKList)
            {
                Console.WriteLine("超市仓库中有:" + item.Count + " 个 " + item[0].name+", 单价为 "+item[0].price);
            }
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SupermarketManagermentSystem
{
    class Banana:ProductBase
    {
        public Banana(double _price, string  _name, string _id) : base(_price, _name, _id)
        {
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SupermarketManagermentSystem
{
    class Acer:ProductBase
    {
        public Acer(double _price, string _name, string _id)
    : base(_price, _name, _id)
        {
        }
    }
}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/909147.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号