2020-12-19

努力了一周的成果:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _1超市收银系统
{
    class ProductFather
    {
        public double Price
        {
            get;
            set;
        }
        public string Name
        {
            get;
            set;
        }

        public string ID
        {
            get;
            set;
        }

        public ProductFather(string id, double price, string Name)
        {
            this.ID = id;
            this.Name = Name;
            this.Price = price;
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _1超市收银系统
{
    class SupperMarket
    {
        public static double Sun = 0;
        CangKu ck = new CangKu();
        public SupperMarket()
        {
            ck.JinPros("ACER", 1000);
            ck.JinPros("SAMSUNG", 1000);
            ck.JinPros("JIANGYOU", 1000);
            ck.JinPros("BANANA", 1000);
        }
        static double realyMoneyone;
        public void AskBuying()
        {
            Console.WriteLine("你好,请问你需要什么?");
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("我们有Acer、SamSung、JiangYou、Banana");
            string strType = Console.ReadLine();
            Console.WriteLine("你需要多少?");
            int count = Convert.ToInt32(Console.ReadLine());
            strType = strType.ToUpper();
            ProductFather[] pros = ck.QuPros(strType, count);
            //计算金额
            double realyMoney = GetMoney(pros);
            Console.WriteLine("你应付{0}", realyMoney);
            Console.WriteLine("你是否需要继续购物,如不需要请输入0 ;如需要请输入除0外任意数字");
            bool b = true;
            while (b)
            {
                try
                {
                    int s = Convert.ToInt32(Console.ReadLine());
                    b = Convert.ToBoolean(s);
                }
                catch
                {
                    Console.WriteLine("你输入的不是数字,请重新输入");
                }
                if (b)
                {
                    realyMoneyone = AskAgain();
                    break;
                }
                else
                    break;
            }
            double sum = 0;
            Console.WriteLine("以下是购物信息");
            foreach (var item in pros)
            {
                Console.WriteLine("货物名称:" + item.Name + "," + "\t" + "货物单价:" + item.Price + "," + "\t" + "货物编号:" + item.ID);
                sum += item.Price;
            }
            sum += realyMoneyone;
            Console.WriteLine("总额为{0}元", sum);
        }
        public CalFather GetCal(string input)//打折选择
        {
            CalFather cal = null;
            while (true)
            {
                try
                {
                    switch (input)
                    {
                        case "1":
                            cal = new CalNormal();
                            break;
                        case "2":
                            cal = new CalRate(0.9);
                            break;
                        case "3":
                            cal = new CalRate(0.85);
                            break;
                        case "4":
                            cal = new CalMN(300, 50);
                            break;
                        case "5":
                            cal = new CalMN(500, 100);
                            break;
                    }
                }
                catch
                {
                    Console.WriteLine("无效结果,请再次输入。");
                }
                break;
            }
            return cal;
        }
        public double GetMoney(ProductFather[] pros)
        {
            double realymoney = 0;
            for (int i = 0; i < pros.Length; i++)
            {
                realymoney += pros[i].Price;
            }
            return realymoney;

        }
        public void ShowPros()
        {
            ck.ShowPros();
        }
        public double AskAgain()
        {
            Console.WriteLine("请问你还需要什么?");
            Console.Clear();
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("我们有Acer、SamSung、JiangYou、Banana");
            string strType = Console.ReadLine();
            Console.WriteLine("你需要多少?");
            int count = Convert.ToInt32(Console.ReadLine());
            strType = strType.ToUpper();
            ProductFather[] pros = ck.QuPros(strType, count);
            //计算金额
            double realyMoneyone = GetMoney(pros);
            Console.WriteLine("你应付{0}", realyMoneyone);
            return realyMoneyone;
        }
        public void Vip()
        {
            Console.WriteLine("你好Vip,请问你需要什么?");
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("我们有Acer、SamSung、JiangYou、Banana");
            string strType = Console.ReadLine();
            Console.WriteLine("你需要多少?");
            int count = Convert.ToInt32(Console.ReadLine());
            strType = strType.ToUpper();
            ProductFather[] pros = ck.QuPros(strType, count);
            //计算金额
            double realyMoney = GetMoney(pros);
            Console.WriteLine("你应付{0}", realyMoney);
            Console.WriteLine("你是否需要继续购物,如不需要请输入0 ;如需要请输入除0外任意数字");
            bool b = true;
            while (b)
            {
                try
                {
                    int s = Convert.ToInt32(Console.ReadLine());
                    b = Convert.ToBoolean(s);
                }
                catch
                {
                    Console.WriteLine("你输入的不是数字,请重新输入");
                }
                if (b)
                {
                    realyMoneyone = AskAgain();
                    break;
                }
                else
                    break;
            }
            Console.WriteLine("现有5种优惠方式供您选择:1.不打折,2.打9折,3.打85折 4.满300元送50元,5.满500元送100元。");
            string input = Console.ReadLine();
            CalFather cal = GetCal(input);
            double totalMoney = cal.GetTotalMoney(realyMoney);
            double sum = 0;
            Console.WriteLine("以下是购物信息");
            foreach (var item in pros)
            {
                Console.WriteLine("货物名称:" + item.Name + "," + "\t" + "货物单价:" + item.Price + "," + "\t" + "货物编号:" + item.ID);
                sum += item.Price;
            }
            sum += realyMoneyone;
            Console.WriteLine("总额为{0}元", sum);
            Console.WriteLine("打完折后,你共应付{0}元", cal.GetTotalMoney(sum));
        }
        public void Admin()
        {
            Console.WriteLine("管理员你好,请问你需要什么?");
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("我们有Acer、SamSung、JiangYou、Banana");
            string strType = Console.ReadLine();
            Console.WriteLine("你需要多少?");
            int count = Convert.ToInt32(Console.ReadLine());
            strType = strType.ToUpper();
            ProductFather[] pros = ck.QuPros(strType, count);
            //计算金额
            double realyMoney = GetMoney(pros);
            Console.WriteLine("你应付{0}", realyMoney);
            Console.WriteLine("你是否需要继续购物,如不需要请输入0 ;如需要请输入除0外任意数字");
            bool b = true;
            while (b)
            {
                try
                {
                    int s = Convert.ToInt32(Console.ReadLine());
                    b = Convert.ToBoolean(s);
                }
                catch
                {
                    Console.WriteLine("你输入的不是数字,请重新输入");
                }
                if (b)
                {
                    realyMoneyone = AskAgain();
                    break;
                }
                else
                    break;
            }
            double sum = 0;
            Console.WriteLine("以下是购物信息");
            foreach (var item in pros)
            {
                Console.WriteLine("货物名称:" + item.Name + "," + "\t" + "货物单价:" + item.Price + "," + "\t" + "货物编号:" + item.ID);
                sum += item.Price;
            }
            sum += realyMoneyone;
            sum *= 0.6;
            Console.WriteLine("你需支付的总额为{0}元", sum);
        }
        public bool Judge(int a)
        {
            if (a == 0)
            {
                Console.WriteLine("请输入账号");
                string zh = Console.ReadLine();
                Console.WriteLine("请输入密码");
                string mm = Console.ReadLine();
                while (zh != "Admin" || mm != "888888")
                {
                    Console.WriteLine("输入有误,将默认你为普通用户");
                    return false;
                }
                return true;
            }
            else
            {
                Console.WriteLine("请输入账号");
                string zh = Console.ReadLine();
                Console.WriteLine("请输入密码");
                string mm = Console.ReadLine();
                while (zh != "Vip" || mm != "888888")
                {
                    Console.WriteLine("输入有误,将默认你为普通用户");
                    return false;
                }
                return true;
            }
            
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _1超市收银系统
{
    class SamSung : ProductFather
    {
        public SamSung(string id, double price, string Name)
            : base(id, price, Name)
        {

        }
    }
    class Acer : ProductFather
    {
        public Acer(string id, double price, string Name)
            : base(id, price, Name)
        {

        }
    }
    class Banana : ProductFather
    {
        public Banana(string id, double price, string Name)
            : base(id, price, Name)
        {

        }
    }
    class JiangYou : ProductFather
    {
        public JiangYou(string id, double price, string Name)
        : base(id, price, Name)
        {

        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _1超市收银系统
{
    class CangKu
    {
        List<List<ProductFather>> list = new List<List<ProductFather>>();
        /*List<SamSung> ListSam = new List<SamSung>();
        List<Acer> ListAcer = new List<Acer>();
        List<JiangYou>ListjiangYou = new List<JiangYou>();
        List<Banana> ListBanana = new List<Banana>();*/
        public void ShowPros()
        {
            try
            {
                foreach (var item in list)
                {
                    Console.WriteLine("仓库有" + item[0].Name + "," + "\t" + "有" + item.Count + "个," + "\t" + "每个" + item[0].Price + "元");
                }
            }
            catch
            {
                Console.WriteLine("仓库有三星手机,       有1000个,       每个2000元");
                Console.WriteLine("仓库有老抽酱油,       有1000个,       每个10元");
                Console.WriteLine("仓库有大香蕉,       有1000个,       每个5元");
            }
        }
        public CangKu()//添加货架
        {
            list.Add(new List<ProductFather>());//泛型集合
            list.Add(new List<ProductFather>());
            list.Add(new List<ProductFather>());
            list.Add(new List<ProductFather>());
        }
        public void JinPros(string strtype, int count)//进货
        {
            for (int i = 0; i < count; i++)
            {
                switch (strtype)
                {
                    case "ACER":
                        list[0].Add(new Acer(Guid.NewGuid().ToString(), 1000, "宏基笔记本"));
                        break;
                    case "SAMSUNG":
                        list[1].Add(new SamSung(Guid.NewGuid().ToString(), 2000, "三星手机"));
                        break;
                    case "JIANGYOU":
                        list[2].Add(new JiangYou(Guid.NewGuid().ToString(), 10, "老抽酱油"));
                        break;
                    case "BANANA":
                        list[3].Add(new Banana(Guid.NewGuid().ToString(), 5, "大香蕉"));
                        break;
                }
            }
        }
        public ProductFather[] QuPros(string strtype, int count)//取货  //返回父类,因为不知道取那种商品,屏蔽差异
        {
            ProductFather[] pros = new ProductFather[count];
            for (int i = 0; i < pros.Length; i++)
            {
                switch (strtype)
                {
                    case "ACER":
                        if (list[0].Count == 0)
                        {
                            Console.WriteLine("抱歉,货物已购空!");
                            break;
                        }
                        pros[i] = list[0][0];
                        list[0].RemoveAt(0);
                        break;
                    case "SAMSUNG":
                        if (list[0].Count == 0)
                        {
                            Console.WriteLine("抱歉,货物已购空!");
                            break;
                        }
                        else
                        {
                            try
                            {
                                pros[i] = list[1][0];
                                list[1].RemoveAt(0);
                            }
                            catch
                            {
                                Console.WriteLine("未知错误");
                            }
                            break;
                        }
                    case "JIANGYOU":
                        if (list[0].Count == 0)
                        {
                            Console.WriteLine("抱歉,货物已购空!");
                            break;
                        }
                        pros[i] = list[2][0];
                        list[2].RemoveAt(0);
                        break;
                    case "BANANA":
                        if (list[0].Count == 0)
                        {
                            Console.WriteLine("抱歉,货物已购空!");
                            break;
                        }
                        pros[i] = list[3][0];
                        list[3].RemoveAt(0);
                        break;
                }
            }
            return pros;
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _1超市收银系统
{
    abstract class CalFather
    {
        public abstract double GetTotalMoney(double realyMoney);
    }
    class CalMN : CalFather
    {
        public override double GetTotalMoney(double realyMoney)
        {
            if (realyMoney >= this.M)
            {
                return realyMoney - (int)(realyMoney / this.M) * this.N;
            }
            else
            {
                return realyMoney;
            }
        }
        public double M
        {
            get;
            set;
        }
        public double N
        {
            get;
            set;
        }
        public CalMN(double M, double N)
        {
            this.M = M;
            this.N = N;
        }
    }
    class CalNormal : CalFather
    {
        public override double GetTotalMoney(double realyMoney)
        {
            return realyMoney;
        }
    }
    class CalRate : CalFather
    {
        /// <summary>
        /// 按折扣打折
        /// </summary>
        public double Rate
        {
            get;
            set;
        }
        public CalRate(double rate)
        {
            this.Rate = rate;
        }
        public override double GetTotalMoney(double realyMoney)
        {
            return realyMoney * this.Rate;
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _1超市收银系统
{
    class CangKu
    {
        List<List<ProductFather>> list = new List<List<ProductFather>>();
        /*List<SamSung> ListSam = new List<SamSung>();
        List<Acer> ListAcer = new List<Acer>();
        List<JiangYou>ListjiangYou = new List<JiangYou>();
        List<Banana> ListBanana = new List<Banana>();*/
        public void ShowPros()
        {
            try
            {
                foreach (var item in list)
                {
                    Console.WriteLine("仓库有" + item[0].Name + "," + "\t" + "有" + item.Count + "个," + "\t" + "每个" + item[0].Price + "元");
                }
            }
            catch
            {
                Console.WriteLine("仓库有三星手机,       有1000个,       每个2000元");
                Console.WriteLine("仓库有老抽酱油,       有1000个,       每个10元");
                Console.WriteLine("仓库有大香蕉,       有1000个,       每个5元");
            }
        }
        public CangKu()//添加货架
        {
            list.Add(new List<ProductFather>());//泛型集合
            list.Add(new List<ProductFather>());
            list.Add(new List<ProductFather>());
            list.Add(new List<ProductFather>());
        }
        public void JinPros(string strtype, int count)//进货
        {
            for (int i = 0; i < count; i++)
            {
                switch (strtype)
                {
                    case "ACER":
                        list[0].Add(new Acer(Guid.NewGuid().ToString(), 1000, "宏基笔记本"));
                        break;
                    case "SAMSUNG":
                        list[1].Add(new SamSung(Guid.NewGuid().ToString(), 2000, "三星手机"));
                        break;
                    case "JIANGYOU":
                        list[2].Add(new JiangYou(Guid.NewGuid().ToString(), 10, "老抽酱油"));
                        break;
                    case "BANANA":
                        list[3].Add(new Banana(Guid.NewGuid().ToString(), 5, "大香蕉"));
                        break;
                }
            }
        }
        public ProductFather[] QuPros(string strtype, int count)//取货  //返回父类,因为不知道取那种商品,屏蔽差异
        {
            ProductFather[] pros = new ProductFather[count];
            for (int i = 0; i < pros.Length; i++)
            {
                switch (strtype)
                {
                    case "ACER":
                        if (list[0].Count == 0)
                        {
                            Console.WriteLine("抱歉,货物已购空!");
                            break;
                        }
                        pros[i] = list[0][0];
                        list[0].RemoveAt(0);
                        break;
                    case "SAMSUNG":
                        if (list[0].Count == 0)
                        {
                            Console.WriteLine("抱歉,货物已购空!");
                            break;
                        }
                        else
                        {
                            try
                            {
                                pros[i] = list[1][0];
                                list[1].RemoveAt(0);
                            }
                            catch
                            {
                                Console.WriteLine("未知错误");
                            }
                            break;
                        }
                    case "JIANGYOU":
                        if (list[0].Count == 0)
                        {
                            Console.WriteLine("抱歉,货物已购空!");
                            break;
                        }
                        pros[i] = list[2][0];
                        list[2].RemoveAt(0);
                        break;
                    case "BANANA":
                        if (list[0].Count == 0)
                        {
                            Console.WriteLine("抱歉,货物已购空!");
                            break;
                        }
                        pros[i] = list[3][0];
                        list[3].RemoveAt(0);
                        break;
                }
            }
            return pros;
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _1超市收银系统
{
    class Program
    {
        static void Main(string[] args)
        {
            SupperMarket sm = new SupperMarket();
            sm.ShowPros();
            Console.WriteLine("请输入你的身份,0普通用户,1Vip,2管理员");
            int a = Convert.ToInt32(Console.ReadLine());
            int judge = 0;
            switch (a)
            {
                case 0:
                    sm.AskBuying();
                    break;
                case 1:
                    judge = 1;
                    bool b=sm.Judge(judge);
                    if (b)
                    {
                        sm.Vip();

                    }
                    else
                    {
                        sm.AskBuying();
                    }
                    break;
                case 2:
                    bool c = sm.Judge(judge);
                    if (c == true)
                    {
                        sm.Admin();
                    }
                    else
                    {
                        sm.AskBuying();
                    }
                    
                    break;
                default:
                    Console.WriteLine("输入有误,将默认你为普通用户");
                    sm.AskBuying();
                    break;
            }
            Console.ReadKey(true);
        }
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值