能力值:
( LV2,RANK:10 )
|
-
-
2 楼
晕啊,作业还要找人帮助,,,
|
能力值:
( LV2,RANK:10 )
|
-
-
3 楼
作业是完成了,但想看看用设计模式写的程序
|
能力值:
( LV2,RANK:10 )
|
-
-
4 楼
这个作业还要求助啊?真的很简单啊。
|
能力值:
( LV2,RANK:10 )
|
-
-
5 楼
表示毫无挑战,不想写了,太简单了。
|
能力值:
( LV2,RANK:10 )
|
-
-
6 楼
你帮忙做一下嘛,用一种设计模式
|
能力值:
( LV2,RANK:10 )
|
-
-
7 楼
服了,作业也在, - -
|
能力值:
( LV2,RANK:10 )
|
-
-
8 楼
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
namespace P290
{
public class Order
{
private string _typeOfPay;//字段定义
private string _shipAddress; //字段定义
private string _shippingMethod; //字段定义
public string OrderId;
public string TypeOfPay //属性定义
{
get { return _typeOfPay; }
set { if (value!=_typeOfPay)
_typeOfPay=value;
}
}
public string ShipAddress //属性定义
{
get { return _shipAddress; }
set
{
if (value != _shipAddress)
_shipAddress= value;
}
}
public string ShippingMethod//属性定义
{
get { return _shippingMethod; }
set
{
if (value != _shippingMethod)
_shippingMethod = value;
}
}
private List<LineItem> _lineItems = new List<LineItem>();//订购项列表
public List<LineItem> LineItem
{
get {return _lineItems;}
}
public Order(string orderId, string typeOfPay, string shipAddress,
string shippingMethod) //有参构造函数
{
OrderId = orderId; //订单编号
TypeOfPay = typeOfPay; //付款方式
ShipAddress = shipAddress; //送货方式
ShippingMethod = shippingMethod; //发货地址
inputLineItems();//输入订单排列项
}
void inputLineItems()
{
while (true)
{
Console.Write("要输入订单数据吗(是按y,否按其它):");
string confirmStr1=Console.ReadLine();
if ( confirmStr1=="y" )
{
Console.WriteLine("输入一条订购记录");
Console.Write("输入商品编号:");
string wareId=Console.ReadLine();
Console.Write("输入商品名称:");
string wareName=Console.ReadLine();
Console.Write("输入品牌:");
string brand=Console.ReadLine();
Console.Write("输入型号规格:");
string specification=Console.ReadLine();
Console.Write("输入单价:");
double price=Convert.ToDouble(Console.ReadLine());
Console.Write("输入数量:");
int amount=Convert.ToInt32(Console.ReadLine());
LineItem theLineItem=new LineItem( wareId, wareName, brand,
specification, price, amount);
_lineItems.Add(theLineItem);
}
else
{
return;
}
}
}
public void PrintMembers()
{
Console.Write("订单编号:{0} ", OrderId);
Console.Write("付款方式:{0} ", _typeOfPay);
Console.Write("送货方式:{0} ", _shippingMethod);
Console.WriteLine("发货地址:{0}", _shipAddress);
Console.WriteLine("----------------------------------------------------------------------");
Console.WriteLine(" 商品编号 | 商品名称 | 品牌 | 型号规格 | 单价 | 数量 ");
foreach (LineItem li in _lineItems)
{
Console.WriteLine("----------------------------------------------------------------------");
Console.Write("{0,10}|", li.WareId);
Console.Write("{0,10}|", li.WareName);
Console.Write("{0,10}|", li.Brand);
Console.Write("{0,10}|", li.Specification);
Console.Write("{0,10}|", li.Price);
Console.WriteLine("{0,10}", li.Amount);
}
Console.WriteLine("----------------------------------------------------------------------");
}
public double calMoneyPayable() //计算应付金额
{
double subtotal=0.0; //列表项金额合计
foreach (LineItem li in _lineItems) //累计列表项折扣优惠前金额
{
subtotal += li.calLineMoney();
}
return subtotal;
}
public double calPostDiscountAmount() //计算折扣后金额
{
//先累计每项折扣
double postDiscount = 0.0; //折扣后列表项金额合计
foreach (LineItem li in _lineItems) //累计列表项折扣后金额
{
postDiscount += li.calPostDiscount();
}
return postDiscount;
}
public double calPostPriviledge(double funds) //计算优惠的金额-实付金额
{
double preferAmount;
if (funds >= 100000 && funds < 200000)
preferAmount = funds * 0.06;
else if (funds >= 200000 && funds < 400000)
preferAmount = funds * 0.08;
else if (funds >= 400000 && funds < 1000000)
preferAmount = funds * 0.10;
else if (funds >= 1000000)
preferAmount = funds * 0.15;
else
preferAmount = 0.0;
return preferAmount;
}
public double calPayAmount() //计算支付金额
{
double payOffAmount;
payOffAmount = calMoneyPayable() - calPostPriviledge(calPostDiscountAmount());//支付金额
return payOffAmount;
}
}
public class LineItem
{
string _wareId;
string _wareName;
string _brand;
string _specification;
double _price;
int _amount;
public LineItem(string wareId, string wareName, string brand,
string specification, double price, int amount)
//有参构造函数
{
_wareId = wareId;
_wareName = wareName;
_brand = brand;
_specification = specification;
_price = price;
_amount = amount;
}
public string WareId{
get { return _wareId; }
}
public string WareName{
get { return _wareName; }
}
public string Brand{
get { return _brand; }
}
public string Specification{
get { return _specification; }
}
public double Price{
get { return _price; }
}
public int Amount{
get { return _amount; }
}
public double calLineMoney()//计算行金额
{
return _price * _amount;
}
public double calPostDiscount()//计算行折扣后金额
{
double postDiscount = calLineMoney();
if (_amount >= 10 && _amount < 50) //10台以上
return postDiscount * 0.99;
else if (_amount >= 50 && _amount < 100)
return postDiscount * 0.98;
else if (_amount >= 100)
return postDiscount * 0.96;
else
return postDiscount;
}
}
class Program
{
static void Main(string[] args)
{
Console.WriteLine("新建一份订单");
Console.Write("输入订单编号:");
string orderId=Console.ReadLine();
Console.Write("输入付款方式:");
string payStyle = Console.ReadLine();
Console.Write("输入送货方式:");
string deliverStyle = Console.ReadLine();
Console.Write("输入送货方式:");
string deliverAddr = Console.ReadLine();
Order theOrder = new Order(orderId, payStyle, deliverStyle, deliverAddr);
theOrder.PrintMembers();
Console.WriteLine("应付金额:{0}",theOrder.calMoneyPayable());
Console.WriteLine("优惠金额:{0}",theOrder.calPostPriviledge(theOrder.calPostDiscountAmount()) );
Console.WriteLine("支付金额:{0}", theOrder.calPayAmount());
Console.ReadLine();
}
}
}
|
能力值:
( LV2,RANK:10 )
|
-
-
9 楼
C#社区???走过了吧
|
能力值:
( LV2,RANK:10 )
|
-
-
10 楼
我想说你去看看clean code吧,好多注释都是没必要的
|
能力值:
( LV2,RANK:10 )
|
-
-
11 楼
草草看了下,果真是作业级的代码,如果你想加点模式,有两个小建议,应该能使你代码增色不少:
1:如果订单除了编号、地址、付款方式之外又想增加新的东西了,怎么办?如果每件商品又增加了新的属性怎么办?你可以尝试用一下建造者模式,并且把“打印”这种功能分解,让每个对象“打印自身”,而不是用总控程序去组装打印;
2:如果优惠金额变化了怎么办?如果有新的优惠措施了(比如满200-100)怎么办?你可以尝试下策略模式。
推荐去看看 大话设计模式,简单易懂,全是小故事……网上有PDF
|
能力值:
( LV2,RANK:10 )
|
-
-
12 楼
|
能力值:
( LV2,RANK:10 )
|
-
-
13 楼
好像百度工厂模式就有类似的例子。不过似乎是c++的就是了
|