思维导图如图所示:

1、商品类(父类)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;namespace 超市收银系统
{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.Price = price;this.Name = name;}}
}

 2、子类(Acer笔记本,酱油,香蕉,三星笔记本)

(i)三星笔记本类

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;namespace 超市收银系统
{class SamSung:ProductFather{public SamSung(string id, double price, string Name) : base(id, price, Name){}}
}

(ii)酱油类

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;namespace 超市收银系统
{class JiangYou:ProductFather{public JiangYou(string id,double price,string Name):base(id,price,Name){}}
}

(iii)香蕉类

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;namespace 超市收银系统
{class Banana:ProductFather{public Banana(string id, double price, string Name) : base(id, price, Name){}}
}

(IV)Acer笔记本类

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;namespace 超市收银系统
{class Acer:ProductFather{public Acer(string id, double price, string Name) : base(id, price, Name){}}
}

3、仓库类

这里的List<List<ProductFather>>表示新建了一个仓库内的货架

Guid.NewGuid().ToString()可以获取到一串不重复的序列码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;namespace 超市收银系统
{class CangKu{/*存储货物*///这样写较为麻烦//List<SamSung> listSam = new List<SamSung>();//List<Acer> listAcer = new List<Acer>();//List<JiangYou> listJiangYou = new List<JiangYou>();//List<Banana> listBanana = new List<Banana>();//一层list表示的是仓库,二层list表示的是仓库里的货架List<List<ProductFather>> list = new List<List<ProductFather>>();//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>public void ShowPros(){foreach (var item in list){Console.WriteLine("我们超市有:" + item[0].Name + "\t" + "有" + item.Count + "个\t" + "每个" + item[0].Price + "元");}}/// <summary>/// 进货/// </summary>/// <param name="strType">货物的类型</param>/// <param name="count">货物的数量</param>public void importPros(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(), 50, "香蕉"));break;}}}/// <summary>/// 从仓库中提取货物/// </summary>/// <param name="strType">货物的种类</param>/// <param name="count">货物的数量</param>/// <returns></returns>public ProductFather[] OutportPros(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) {pros[i] = list[0][0];list[0].RemoveAt(0);}break;case "SamSung":if (list[1].Count != 0){pros[i] = list[1][0];list[1].RemoveAt(0);}break;case "JiangYou":if (list[2].Count != 0){pros[i] = list[2][0];list[2].RemoveAt(0);}break;case "Banana":if (list[3].Count != 0){pros[i] = list[3][0];list[3].RemoveAt(0);}break;}}return pros;}}
}

4、打折类(抽象父类)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;namespace 超市收银系统
{/// <summary>/// 打折的父类/// </summary>abstract class CalFather{/// <summary>/// 计算打折后应付多少钱/// </summary>/// <param name="realMoney">打折前应付的价钱</param>/// <returns>打折后应付的钱</returns>public abstract double GetTotalMoney(double realMoney);}
}

(i)不打折(继承抽象父类,重写打折后价格)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;namespace 超市收银系统
{/// <summary>/// 不打折 该多少钱就多少钱/// </summary>class CalNormal:CalFather{public override double GetTotalMoney(double realMoney){return realMoney;}}
}

(ii)打折(继承抽象父类,重写打折后价格)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;namespace 超市收银系统
{/// <summary>/// 按折扣率打折/// </summary>class CalRate:CalFather{public double Rate{get;set;}public CalRate(double rate){this.Rate = rate;}public override double GetTotalMoney(double realMoney){return realMoney * this.Rate;}}
}

(iii)满M元减N元(继承抽象父类,重写打折后价格)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;namespace 超市收银系统
{class CalMN:CalFather{//买500送100public double M{get;set;}public double N{get;set;}public CalMN(double m, double n){this.M = m;this.N = n;}public override double GetTotalMoney(double realMoney){if (realMoney >= this.M){return realMoney - (int)(realMoney / this.M) * this.N; //realMoney/this.M意思为 买M送N,如果买2M则送2N}else{return realMoney;}}}
}

4、超市收银类

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;namespace 超市收银系统
{class SupperMarket{CangKu ck = new CangKu();/// <summary>/// 创建超市对象的时候,给仓库的货架上导入货物/// </summary>public SupperMarket(){ck.importPros("SamSung", 100);ck.importPros("JiangYou", 50);ck.importPros("Banana", 10);ck.importPros("Acer", 6);}/// <summary>/// 跟用户交互的过程/// </summary>public void AskBuying(){Console.WriteLine("欢迎光临,请问您需要什么?");Console.WriteLine("我们有 Acer、SamSung、JiangYou、Banana");string strType = Console.ReadLine();Console.WriteLine("您需要多少?");int count = Convert.ToInt32(Console.ReadLine());//去仓库取货ProductFather[] pros = ck.OutportPros(strType, count);//下面该计算价钱了double realMoney = GetMoney(pros);Console.WriteLine("您总共应付{0}元", realMoney);Console.WriteLine("请选择您的打折方式 1——不打折 2——打9折 3——打85折 4——买300送50 5——买500送100");string input = Console.ReadLine();//通过简单工厂的设计模式根据用户的输入获得一个打折对象CalFather cal = GetCal(input);double totalMoney = cal.GetTotalMoney(realMoney);Console.WriteLine("打完折后,您应付{0}元", totalMoney);Console.WriteLine("以下是您的购物信息");foreach (var item in pros){Console.WriteLine("货物名称:" + item.Name + "," + "\t" + "货物单价:" + item.Price + "," + "\t" + "货物编号:" + item.ID);}}/// <summary>/// 根据用户的选择打折方式返回一个打折对象/// </summary>/// <param name="input">用户的选择</param>/// <returns>返回的父类对象 但是里面装的是子类对象</returns>public CalFather GetCal(string input){CalFather cal = null;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;}return cal;}/// <summary>/// 根据用户买的货物计算总价钱/// </summary>/// <param name="pros"></param>/// <returns></returns>public double GetMoney(ProductFather[] pros){double realMoney = 0;for (int i = 0; i < pros.Length; i++){realMoney += pros[i].Price;}return realMoney;}public void ShowPros(){ck.ShowPros();}}
}

5、主程序运行

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;namespace 超市收银系统
{class Program{static void Main(string[] args){SupperMarket sm = new SupperMarket();//展示货物sm.ShowPros();//跟用户交互sm.AskBuying();}}
}

运行结果

学习教程:【01_C#入门到精通】新手强烈推荐:C#开发课程,一整套课程_哔哩哔哩_bilibili

整个案例非常适合对面向对象学习总结,这种编程方式可拓展性比较强。

目前只支持一次购买一种商品,后续可拓展一次购买多个商品等功能

C# 超市收银系统——面向对象学习的总结相关推荐

  1. 超市收银系统服务器搭建教程,超市收银系统快速收银步骤? 你需要学习了

    超市收银系统,适用行业:超市.便利店.百货店等. 现在收银员换工作比较频繁,稳定性不高.刚刚熟悉收银系统,过几天就走人了.又要重新招聘新员工,收银速度慢,客人排队现象比较严重,而且新手容易出错. 如何 ...

  2. 实现断网收银_2019连锁超市收银系统前5名

    连锁超市.连锁便利店已经是零售便利商超发展的必然趋势.不可阻挡,而随着店面的扩大,店铺的经营范围.影响力都在扩大,包括员工自身的口碑营销,都在对门店进行营销和推广.而随着连锁便利商超的繁荣发展,越来越 ...

  3. 基于JSP的超市收银系统

    技术:Java.JSP等 摘要: 随着经济的发展和人口的增长,人们对于日常生活的便捷与舒适程度有了越来越高的要求.据统计,在大中型城市,人们日常生活用品大多在超市采购,超市因其物品的丰富性.选择的自主 ...

  4. C#实现超市收银系统(窗口化)(1)

    题目:提供多种商品(6种以上),不同的商品可以设置不同的促销模式,任选其一 (1. 不参与任何优惠 2.打折(9折) 3.满减(满100减20) 4. 满减后再打折(满100减20再打9折)) 要求: ...

  5. 超市收银程序_超市收银系统案例|千平超市再开2家,星耀助力门店年关创收...

    思迅天店星耀版收银系统案例_超市收银系统:千平超市再开2家,星耀助力门店年关创收 年关冲刺,收银压力,库存管理...... 都是现在超市老板们的工作重点 近期开业 横溪购物中心和汇隆购物广场 妥妥的千 ...

  6. 收银系统 mysql数据库_某大型超市收银系统数据库成功恢复

    SQL数据库表结构成功修复 [用户单位] 昆明某大型超市 [数据恢复故障描述] 由于操作系统错误,导致系统无法正常使用, 技术员在维护过程中不小心把整个磁盘初始化, 磁盘数据全部丢失,导致超市收银系统 ...

  7. C/C++超市收银系统

    C/C++超市收银系统 (三)超市收银系统程序设计 要求: 1)都有菜单页,有用户登录和退出环节,有退出系统菜单项; 2)采用结构体数组变量完成数据的储存(用动态分配结构体数组或单向链表加分) 3)至 ...

  8. 超市收银系统c语言程序用c 的,C语言 超市收银系统

    C语言写的超市收银系统,结构体储存数据 --------------------------------------- 时间:2015-7-1 16:44:21 吴俊龙 C语言专周设计 超市收银系统 ...

  9. java编写超市收银系统_java编写的超市收银系统

    [实例简介] 用java编写的超市收银系统, [实例截图] [核心代码] ad9ea874-4694-4cc4-b634-760c9c1b6b65 └── 超市收银系统 ├── sql │   ├── ...

最新文章

  1. 自定义标签 (choose)
  2. c语言getchar函数_C语言中带有示例的getchar()函数
  3. Qt 自定义界面(实现无边框、可移动)
  4. 自动驾驶路径规划论文解析(2)
  5. 睡眠多少分钟一个循环_睡眠分为几个阶段每个阶段大概多少时间?
  6. IComparable和Icomparer接口
  7. 10 倍高清不花!大麦端选座 SVG 渲染
  8. java中主函数_(基础)java中的主函数
  9. Mac Xdebug安装时遇到了Zend Engine API 不一致的问题
  10. P5231 [JSOI2012]玄武密码
  11. javaweb响应内容类型分析工具(tomcat)
  12. 低代码开发平台+KM知识文档管理系统搭配的好处
  13. java毕业生设计疫苗药品批量扫码识别追溯系统计算机源码+系统+mysql+调试部署+lw
  14. 图像修复 : ICCV 2021 基于条件纹理和结构并行生成的图像修复【翻译】
  15. Android掌上医疗预约挂号系统app
  16. 什么是数据流图 Data Flow Diagram (DFD)
  17. 系统流量变化的原因与微型气泵的关系
  18. 基于单片机的智能控温风扇系统设计
  19. lambda :: 和计算list中某个字段值的总和
  20. 经济金融投资计量与数据分析Python应用

热门文章

  1. 谈谈如何通过linux系统RHCE考试
  2. Atlas200dk刷机
  3. JS中2种定时器的使用及清除
  4. teamviewer linux远程开机,一分钟就能学会用手机远程控制你的电脑,远程开关机就是这么简单...
  5. python多线程截取音频文件片段,输出指定比特率的mp3文件,很好用
  6. Kotlin创建DSL
  7. jobing:经典逻辑训练题(40-75)(持续解答)
  8. PSVR设计不让玩家来回走动的原因
  9. 上古卷轴 5 :雪瓶的效果
  10. mock(在线接口 MOCK 平台)