如用支付宝在淘宝上购物,一件物品的支付价格为98元,其中支付手续费率为
0.3%(收取卖方),一次购买4件,如要求其中一件物品要求退货,请总结出支付与退款的算法,并做出结果。
备注:1,所有金额保留小数点后两位小数,四舍五入。
2,可连续多次退货。
      3,退款时,支付宝也会退回相应手续费

解决方案 »

  1.   

    买n件 退货m (m <= n)  单价: p买方支付: (n - m) * p
    手续费: (n - m) * p * 0.3%
    卖方收: (n - m) * p * 99.7% 
    int n = 4;
                int m = 0;
                double p = 98;            double payoff = 0;              //买方支付
                double expay = 0;             //手续费
                double rece = 0 ;             //卖方收            Console.WriteLine("已经选购{0}件",n);
                while (true)
                {
                    Console.WriteLine("输入退货数量:(输入Q or q退出)");
                    int i = 0;
                    String str = Console.ReadLine().Trim();
                    if (str == "Q" || str.ToUpper() == "Q")
                        break;                if (!Int32.TryParse(str, out i))
                        continue;
                    else
                    {
                        m += i;
                        if (m == n)
                        {
                            Console.WriteLine("已经全部退货");
                            break;
                        }
                        
                        if (m > n)
                        {
                            Console.WriteLine("退货数量大于已购数量");
                            continue;
                        }
                    }
                }
                payoff = n * p;             
                expay = (n - m) * p * 0.003;  
                rece = (n - m) * p * 0.997;            Console.WriteLine("买方支付: " + payoff.ToString("0.00"));
                Console.WriteLine("手续费: " + expay.ToString("0.00"));
                Console.WriteLine("卖方收: " + rece.ToString("0.00"));
      

  2.   

    //支付
    public void OrderPay(decimal unitPrice,int amount){
    decimal totalPrice = unitPrice*amount;
    decimal handlingFee = totalPrice*0.3;
    decimal actuallyPay = totalPrice-handlingFee;
    //添加数据
    }//退款
    public void Reimburse(int OrderID,int amount){
    //获取订单数据
    OrderInfo objOrder=GetOrder(OrderID);
    decimal reduceMoney = objOrder.unitPrice*amount;
    decimal reduceHandlingFee=reduceMoney*0.3;
    objOrder.actuallyPay = objOrder.actuallyPay - reduceMoney + reduceHandlingFee;
    //更新数据
    }