C#控制台版超市购物系统

来源:互联网 发布:ssl tls算法缺陷漏洞 编辑:程序博客网 时间:2024/06/11 11:15
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace shop
{


    class Product
    {
        private int num;


        public int Num
        {
            get { return num; }
            set { num = value; }
        }
        private string name;


        public string Name
        {
            get { return name; }
            set { name = value; }
        }
        private double price;


        public double Price
        {
            get { return price; }
            set { price = value; }
        }


        //显示自身信息
        public virtual void Show()
        {
            Console.WriteLine("编号:{0}\t名称:{1}\t价格{2}",num,name,price);
        }




    }


    class Apple : Product
    {
        private string form="山西";


        public string Form
        {
            get { return form; }
            set { form = value; }
        }


        private string brand="红富士";


public string Brand
{
  get { return brand; }
  set { brand = value; }
}






        public Apple()
        {
            this.Num = 1;
            this.Name = "苹果";
            this.Price = 5;
        }


        public override void Show()
        {
            Console.WriteLine("编号:{0}\t名称:{1}\t价格:{2}\t品牌:{3}\t产地:{4}",Num,Name,Price,brand,form);
        }


    }


    class Noodle : Product
    {
        private string brand = "康师傅";


        public string Brand
        {
            get { return brand; }
            set { brand = value; }
        }


        string text = "牛肉味";


        public string Text
        {
            get { return text; }
            set { text = value; }
        }


        public Noodle()
        {
            Num = 2;
            Name = "泡面";
            Price = 3;
        }


        public override void Show()
        {
            Console.WriteLine("编号:{0}\t名称:{1}\t价格:{2}\t品牌:{3}\t口味:{4}",Num,Name,Price,brand,text);
        }
    }


    class Banana : Product
    {
        string type = "霸王蕉";


        public string Type
        {
            get { return type; }
            set { type = value; }
        }


        string from = "香港";


        public string From
        {
            get { return from; }
            set { from = value; }
        }


        public Banana()
        {
            Num = 3;
            Name = "香蕉";
            Price = 4;
        }


        public override void Show()
        {
            Console.WriteLine("编号:{0}\t名称:{1}\t价格:{2}\t种类:{3}\t产地:{4}",Num,Name,Price,Type,From);
        }
    }
    class Program
    {
        static void Main(string[] args)
        {


            List<Product> shopList = new List<Product>();
            
            Console.WriteLine("**********************坑爹超市***********************");
            Apple a = new Apple();
            a.Show();
            Noodle n = new Noodle();
            n.Show();
            Banana b = new Banana();
            b.Show();
            Console.WriteLine("*****************************************************");


            while (true)
            {
                Console.WriteLine("请输入商品编号:(输入是0结束购买)");
                 int th= int.Parse(Console.ReadLine());
                 if (th==0)
                 {
                     break;
                 }
                else if (th==1)
           {
                    shopList.Add(a);
                }
                 else if (th==2)
                 {
                     shopList.Add(n);
                 }
                 else if (th==3)
                 {
                     shopList.Add(b);
                 }


            }
            Console.WriteLine("*****************欢迎光临坑爹超市********************");
            Console.WriteLine("坑爹超市清单不坑爹,清单如下:");
            double sum=0;
            for (int i = 0; i < shopList.Count; i++)
            {
               sum+=shopList[i].Price;
            }
            foreach (Product item in shopList)
            {
                item.Show();
            }
            Console.WriteLine("总价:{0}",sum);
        }
    }
}