概述
GUID:
产生一个不会重复的ID
static void Main(string[] args) { //产生一个不会重复的编号 Console.WriteLine(Guid.NewGuid().ToString()); Console.WriteLine(Guid.NewGuid().ToString()); Console.WriteLine(Guid.NewGuid().ToString()); Console.WriteLine(Guid.NewGuid().ToString()); Console.WriteLine(Guid.NewGuid().ToString()); Console.ReadKey(); }
分析:
父类:全用的是自动属性
public class ProductFather { public double Price { get; set; } public string Name { get; set; } public double Count { get; set; } public string ID { get; set; } public ProductFather(string id, double price, double count,string name) { this.ID = id; this.Price = price; this.Count = count; this.Name = name; } }
子类:Acer
class Acer : ProductFather { public Acer(string id, double price, double count, string name) : base(id, price, count, name) { } }
子类:SumSung
class Acer : ProductFather { public Acer(string id, double price, double count, string name) : base(id, price, count, name) { } }
子类:JiangYou
class JiangYou : ProductFather { public JiangYou(string id, double price, double count, string name) : base(id, price, count, name) { } }
子类:Banana
class Banana : ProductFather { public Banana(string id, double price, double count, string name) : base(id, price, count, name) { } }
仓库类:
class CangKu { //List<ProductFather> list = new List<ProductFather>(); //存储货物 //list接收的是List<>,相当于货架 List<List<ProductFather>> list = new List<List<ProductFather>>(); /// <summary> /// 向用户展示货物 /// </summary> public void ShowPros() { foreach (var item in list) { Console.WriteLine("仓库现有:" + item[0].Name + "," + "t" + item.Count + "个," + "t" + "每个" + item[0].Price + "元。"); } } //list[0]存储Acer电脑 list[1]存储三星手机 list[2]存储酱油 list[3]存储香蕉 /// <summary> /// 在创建仓库对象的时候,向仓库中添加货架 /// </summary> public CangKu() { list.Add(new List<ProductFather>()); list.Add(new List<ProductFather>()); list.Add(new List<ProductFather>()); list.Add(new List<ProductFather>()); } /// <summary> /// 进货 /// </summary> /// <param name="strType">货物的类型</param> /// <param name="count">货物的数量</param> 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, 100,"宏基笔记本电脑")); break; case "SamSung": list[1].Add(new SamSung(Guid.NewGuid().ToString(), 2000, 300,"三星手机")); break; case "JiangYou": list[2].Add(new JiangYou(Guid.NewGuid().ToString(), 10, 3000,"老抽")); break; case "Banana": list[3].Add(new Banana(Guid.NewGuid().ToString(), 12, 1000,"香蕉")); break; } } } /// <summary> /// 取货 /// </summary> /// <param name="strType">货物的类型</param> /// <param name="count">数量</param> public ProductFather[] QuPros(string strType, int count) { ProductFather[] pros = new ProductFather[count]; for (int i = 0; i < count; i++) { switch (strType) { case "Acer": //判断如果货物数量为0,提示缺货 if (list[0].Count == 0) { Console.WriteLine("缺货"); } else { pros[i] = list[0][0]; list[0].RemoveAt(0); } break; case "SamSung": if (list[1].Count == 0) { Console.WriteLine("缺货"); } else { pros[i] = list[1][0]; list[1].RemoveAt(0); } break; case "JiangYou": if (list[2].Count == 0) { Console.WriteLine("缺货"); } else { pros[i] = list[2][0]; list[2].RemoveAt(0); } break; case "Banana": if (list[3].Count == 0) { Console.WriteLine("缺货"); } else { pros[i] = list[3][0]; list[3].RemoveAt(0); } break; } } return pros; } }
转载于:https://www.cnblogs.com/mikie/p/4610804.html
最后
以上就是强健烤鸡为你收集整理的.Net学习笔记----2015-06-30(超市收银系统01-仓库类)的全部内容,希望文章能够帮你解决.Net学习笔记----2015-06-30(超市收银系统01-仓库类)所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复