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();
        /// <summary>
        /// 在仓库中存入电脑手机酱油香蕉各1000
        /// </summary>
       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;
            }

        }
        /// <summary>
        /// 计算顾客购买商品的价钱
        /// </summary>
        /// <returns></returns>
        public double GetMoney(ProductBase[] products)
        {
            double money = 0;
            for(int i=0;i<products.Length;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
    {
        /// <summary>
        /// 自动属性--价格
        /// </summary>
         public double price
        {
            set;
            get;
        }
        /// <summary>
        /// 自动属性--商品名称
        /// </summary>
        public string name
        {
            set;
            get;
        }
        /// <summary>
        /// 自动属性--编号
        /// </summary>
        public string id
        {
            set;
            get;
        }
        /// <summary>
        /// 构造函数,用于类的初始化
        /// </summary>
        /// <param name="_price"></param>
        /// <param name="_count"></param>
        /// <param name="_id"></param>
        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
{
    /// <summary>
    /// 打折父类
    /// </summary>
   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<ProductBase>> CKList = new List<List<ProductBase>>();
        /// <summary>
        /// 初始化函数中,将货架存入仓库中
        /// 其中:CKList[0]存储 Acer电脑
        ///           CKList[1]存储 Samsung手机
        ///           CKList[2]存储 酱油JiangOil
        ///           CKList[3]存储 香蕉Banana
        /// </summary>
        public CangKu()
        {
            CKList.Add(new List<ProductBase>());
            CKList.Add(new List<ProductBase>());
            CKList.Add(new List<ProductBase>());
            CKList.Add(new List<ProductBase>());
        }
        /// <summary>
        /// 往仓库中存放货物
        /// </summary>
        public void CunProducter(string strtype,int count)
        {
            for(int i=0;i<count;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;
                }
            }
        }
        /// <summary>
        /// 从仓库中取出货物
        /// </summary>
        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;
        }
        /// <summary>
        /// 显示超市仓库中的货物清单
        /// </summary>
        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)
        {
        }
    }
}

  • 6
    点赞
  • 41
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

XiZhi_BUAA

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值