根据保单日期和分期日期每月计算罚款金额

时间:2016-07-27 09:19:12

标签: c#

假设一个人在public boolean isConnected(){ ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = cm.getActiveNetworkInfo(); if ( networkInfo != null && networkInfo.isConnectedOrConnecting()){ return true; }else{ return false; } } 的下一个分期付款日期为27/07/2016时购买了政策 如果没有在分期付款的人,则延期15天给他支付分期付款 如果他没有这样做,他必须罚款,即2%的保单金额。

现在的情况是 -

27/08/2016 =未支付,
27/09/2016 =未支付,
2016年10月27日=支付前两个月的罚款。

那么如何在c#

中计算出来

1 个答案:

答案 0 :(得分:0)

这样的事情应该这样做。

    public decimal CalculatePayment()
    {
        DateTime lastPaymentDueDate = new DateTime(2016, 7, 27);
        DateTime thisPaymentDate = new DateTime(2016, 10, 27);

        decimal policy = 10000.0M;
        decimal mthFee = 5000.0M;
        decimal mthFine = policy * 2.0M / 100.0M;
        decimal payAmount = 0.0M;
        DateTime nextPaymentDueDate = lastPaymentDueDate.AddMonths(1);

        int thisPayJulian = (int)thisPaymentDate.ToOADate();
        int nextDueJulian = (int)nextPaymentDueDate.ToOADate();

        if (thisPayJulian < nextDueJulian)
        {
            //nothing to pay
            return payAmount;
        }
        while (thisPayJulian - nextDueJulian > 15)
        {
            //deal with late payments
            payAmount += mthFine + mthFee;
            nextPaymentDueDate = nextPaymentDueDate.AddMonths(1);
            nextDueJulian = (int)nextPaymentDueDate.ToOADate();
        }
        if (thisPayJulian >= nextDueJulian)
        {
            //deal with regular payments
            payAmount += mthFee;
        }
        return payAmount;
    }

显然在现实世界中,lastPaymentDueDate,thisPaymentDate和策略,费用和精细百分比都是参数,而不是固定变量,但我希望你明白这一点。

但是,我必须重新审视其他评论:一般来说,如果你没有表现出比自己更多的代码,那么人们不太愿意提供帮助。

相关问题