购物系统
商品类
namespace ShoppingSystem
{
/*
* 商品信息包括:商品名称、商品价格、商品型号、商品描述等
*/
/// <summary>
/// 商品类
/// </summary>
class Goods
{
/// <summary>
/// 商品名称
/// </summary>
private string goodName;
/// <summary>
/// 商品价格
/// </summary>
private float goodPrice;
/// <summary>
/// 商品型号
/// </summary>
private string[] goodModel = new string[2];
/// <summary>
/// 商品类别
/// </summary>
private string goodType;
/// <summary>
/// 商品描述
/// </summary>
private string goodDescribe;
/// <summary>
/// 卖家
/// </summary>
private Seller seller;
public Seller Seller
{
get
{
return seller;
}
set
{
seller = value;
}
}
public string GoodName
{
get
{
return goodName;
}
set
{
goodName = value;
}
}
public float GoodPrice
{
get
{
return goodPrice;
}
set
{
goodPrice = value;
}
}
public string[] GoodModel
{
get
{
return goodModel;
}
set
{
goodModel = value;
}
}
public string GoodType
{
get
{
return goodType;
}
set
{
goodType = value;
}
}
public string GoodDescribe
{
get
{
return goodDescribe;
}
set
{
goodDescribe = value;
}
}
/// <summary>
/// 构造函数,对各个变量赋值并添加商品描述
/// </summary>
/// <param name="goodName">商品名</param>
/// <param name="goodPrice">商品价格</param>
/// <param name="goodId">商品编号</param>
/// <param name="goodModel">商品型号</param>
/// <param name="goodType">商品类别</param>
public Goods(string goodName, float goodPrice, string[] goodModel, string goodType)
{
this.goodName = goodName;
this.goodPrice = goodPrice;
this.goodModel = goodModel;
this.goodType = goodType;
goodDescribe = goodName + goodModel[0] + "|" + goodModel[1] + "|" + goodPrice + "|";
}
}
}
商品总库
namespace ShoppingSystem
{
class GoodsSql
{
/// <summary>
/// 商品总库
/// </summary>
private Goods[] good = new Goods[20];
public Goods[] Good
{
get
{
return good;
}
set
{
good = value;
}
}
}
}
用户类
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ShoppingSystem
{
/// <summary>
/// 用户类
/// </summary>
class User
{
/// <summary>
/// 用户名
/// </summary>
private string username;
/// <summary>
/// 用户余额
/// </summary>
private float userBalance;
/// <summary>
/// 购物车
/// </summary>
private ShoppingCart cart = new ShoppingCart();
public User(string username, float userBalance)
{
this.username = username;
this.userBalance = userBalance;
cart.User = this;
}
public string Username
{
get
{
return username;
}
set
{
username = value;
}
}
public float UserBalance
{
get
{
return userBalance;
}
set
{
userBalance = value;
}
}
public ShoppingCart Cart
{
get
{
return cart;
}
set
{