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);
}
}
}
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);
}
}
}
- C#控制台版超市购物系统
- 超市购物管理系统
- 超市购物系统
- c#之超市系统之超市仓库
- C#学习超市系统之超市前台
- C#学习超市系统之超市商品
- C#练习--实现超市购物结算
- 超市购物
- 【UML】案例分析:新型超市购物自助系统
- 小型超市网上购物系统开发项目总结
- c#练习之超市收银系统
- 基于C#的超市收银管理系统
- C#小项目:模拟超市收银系统
- 超市购物预测
- CSU 1086 超市购物
- 超市购物简例
- csu----超市购物
- C#控制台 系统日志
- POJ1269 Intersecting Lines
- 计数排序
- C/C++经典面试题总结摘选 C/C++程序员面试宝典(一)
- C#接口
- 适配器模式(Adapter)
- C#控制台版超市购物系统
- NJUST4316(立体几何投影的面积交)
- Android TableLayout 释义
- oracle中decode和case when的区别
- 在DOS环境下运行sphinx4当中的回归测试失败的原因
- iphone开发学习,iphone5页面适配修改
- 计算验证条形码(Ean-13码)
- iphone5适配
- 对html元素进行监听