首页
社区
课程
招聘
[旧帖] [求助]求C#作业源码 0.00雪花
发表于: 2013-1-5 19:09 1997

[旧帖] [求助]求C#作业源码 0.00雪花

2013-1-5 19:09
1997
1.拓展训练任务描述
创建一个名称为0rder的类,该类包含以下成员:
①成员变量:订单编号(商品编号、商品名称、品牌、型号规格、单价、数量,这些成员变量根据需要设置合适的可访问特性。
②构造函数:无参构造函数和有参构造函数。
③类的属性:付款方式、送货方式和发货地址属性。
④类的方法:输出成员变量值的方法、计算折扣的方法、计算支付金额的方法。
利用类Order的有参构造函数创建订单对象shopping,调用类的方法输出一个订单对象基本信息,另外使用类的WriteLine()方法输出一个顶单对象的订单编号、付款方式、发货地址、折扣金额和支付金额等数据。
【提示】 一个订单的数据如表所示。            
订单编号:001 付款方式:货到付款 送货方式:免费送货 发货地址:湖南长沙五一路28号
商品编号        商品名称        品牌        型号规格        单价        数量
t37001        彩电        长虹        LT37866        7990.00        1
a2002        空调        海信        KFR-50LW/99HBP        6890.00        1
wqO05        洗衣机        海尔        XQG50-Q1086        4000.00        1
蓝天网上电器商城销售折扣规定如下:
(1)一次性订购相同型号、规格、花色空调的价格优惠
10台以上(含10台)优惠1%,50台以上(含50台)优惠2%,优惠。100台以上(含100台)优惠4%。
(2)累计金额的优惠
累计金额在10~万元优惠6%,累计金额在~40万元优惠8%,累计金额在40~100万元优惠10%,累计金额在100万元以上优惠15%。
要求用到一种设计模式,求教各位了,谢谢,弱弱问一句c#
会不会溢出啊,好像有保护,上面的题目需不需要用异常处理

[课程]FART 脱壳王!加量不加价!FART作者讲授!

收藏
免费 0
支持
分享
最新回复 (12)
雪    币: 38
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
2
晕啊,作业还要找人帮助,,,
2013-1-5 21:47
0
雪    币: 332
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
3
作业是完成了,但想看看用设计模式写的程序
2013-1-5 23:59
0
雪    币: 32
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
4
这个作业还要求助啊?真的很简单啊。
2013-1-6 09:05
0
雪    币: 4031
活跃值: (47)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
5
表示毫无挑战,不想写了,太简单了。
2013-1-6 09:36
0
雪    币: 332
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
6
你帮忙做一下嘛,用一种设计模式
2013-1-6 09:36
0
雪    币: 267
活跃值: (34)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
7
服了,作业也在, - -
2013-1-6 09:38
0
雪    币: 332
活跃值: (10)
能力值: ( 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();
        }
    }
}
2013-1-6 15:40
0
雪    币: 652
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
9
C#社区???走过了吧
2013-1-6 16:30
0
雪    币: 33
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
10
我想说你去看看clean code吧,好多注释都是没必要的
2013-1-7 19:45
0
雪    币: 37
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
11
草草看了下,果真是作业级的代码,如果你想加点模式,有两个小建议,应该能使你代码增色不少:

1:如果订单除了编号、地址、付款方式之外又想增加新的东西了,怎么办?如果每件商品又增加了新的属性怎么办?你可以尝试用一下建造者模式,并且把“打印”这种功能分解,让每个对象“打印自身”,而不是用总控程序去组装打印;

2:如果优惠金额变化了怎么办?如果有新的优惠措施了(比如满200-100)怎么办?你可以尝试下策略模式。

推荐去看看 大话设计模式,简单易懂,全是小故事……网上有PDF
2013-1-9 20:15
0
雪    币: 332
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
12
谢谢
2013-1-14 10:12
0
雪    币: 215
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
13
好像百度工厂模式就有类似的例子。不过似乎是c++的就是了
2013-1-14 10:36
0
游客
登录 | 注册 方可回帖
返回
//