利息计算 [英] interest calculation

查看:116
本文介绍了利息计算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我得到的。不同帐户类型的Customer类对象的LinkedList(Savings,current和fixed)。每个Customer对象都有一个LinkedList of transactions(另一个类)作为属性。可以进行2种交易,即借记(提款)或信用(存款)。鉴于:储蓄账户可能会变为负数,而其他两个账户则不能。允许从固定帐户中扣除任何借记交易(不提取)。

Here's what I got. A linkedList of objects of Customer class of different account types (Savings,current and fixed). Each Customer object has a LinkedList of transactions(another class) as an attribute. 2 types of transactions can be made i.e Debit(withdrawal) or Credit(deposit). Given: A savings account can go into negative while the other two accounts can not. No debit transactions (no withdrawals) from the Fixed account allowed.

如果账户余额为正,那么利率为0.0003,而如果账户余额为负(只有储蓄账户可用),则费率为-0.002。利息计算如下:

if the account balance is positive then the interest rate is 0.0003 while if the account balance is negative (only possible for Saving account)the rate is -0.002. The interest is calculated as follows:

对于正面利息,它基于过去24小时内账户中有
的资金(即来自午夜到午夜)。例如,如果
你在0小时就有100美元,但是你在第1小时已经提取了50美元并且在第2小时存回了50美元b $ b,你将被视为只有50美元在你的账户中停留24小时当天结束
(24小时)。在第24小时,您账户中的资金将为100美元加上按$ 50计算的每日
利息。

For positive interest, it is based on the money that has been in the account for the last 24 hours (i.e. from midnight to midnight). For example, if you have $100 at hour 0 but you have withdrawn $50 at hour 1 and deposited back $50 at hour 2, you will be seen as having only $50 staying in your account for 24 hours at end of the day (hour 24). At hour 24, the money in your account will be $100 plus the daily interests computed according to $50.

对于负利息,它基于总和那天你欠银行b $ b的最大负债。如果您从银行借钱,即使您在1分钟后退还款项,他们也会向您收取
的利息。例如,如果您的储蓄账户在0小时时有
$ 100,但您在22小时时提取200美元,然后在
23时存入1000美元。截至今晚午夜,您将无法获得任何正面利息。将从银行借入100美元的b $ b $负债利息。

For negative interest, it is based on the sum of the largest negative money that you owe the bank on that day. If you borrow money from the bank, they will charge you interest even if you return the money 1 minute later. For example, if your saving account has $100 at hour 0 but you withdraw $200 at hour 22 and then deposit $1000 back at hour 23. You will not be paid any positive interest by today mid-night but will be charged for negative interest for borrow $100 from the bank for today.

对于最初为566.00美元的储蓄账户,账户上的交易如​​下:
借记:50(日期:11-09-2008),借方:500(15-09-2008);信用:200(22-09-2008);借记:500(23-09-2008)。

For a savings account with initially $566.00 and transactions on the account are as follows: debit:50 (date:11-09-2008), debit:500(15-09-2008); credit:200(22-09-2008); debit:500(23-09-2008 ).

样本计算如下:

(( (566 * 1.0003 ^ 10-50)* 1.0003 ^ 4-500)* 1.0003 ^ 8 + 200-500)* 1.002 ^ 8~ = 286.17。

(((566*1.0003^10-50)*1.0003^4-500)*1.0003^8+200-500)*1.002^8 ~= 286.17.

我得到一些1377.68的数字显然不匹配。

I get some figure of the order of 1377.68 which obviously doesn't match.

这是我的拥有对于储蓄账户,但我很确定这是错的。我的问题是如何在循环每个客户的交易时计算利息。我的计算错了。所以我很感激,如果有人可以帮我修复逻辑

Here's what i have for the savings account but i'm pretty sure it's wrong. My question is how to calculate the interest when looping through the transactions for each customer. my calculation is wrong. so i would appreciate it if someone can help me fix the logic

    public void update(double rate){ // Savings account interest calc
         Transactions ctr = new Transactions();
         Node<Transactions> counter = new Node<Transactions>(ctr);
         counter=this.trans.head;
         int i=0;
         double negRate = -0.002;
         double posRate = 0.0003;
         double updatedBal = this.get_balance();
         while(counter!=null){
             if (updatedBal >0){
                if(trans.getItem(i).AccType.equals("Crebit")){
                   double exponent = Double.parseDouble(trans.getItem(i).get_Date().substring(0, 2));
                   updatedBal= (updatedBal*(Math.pow((1+ posRate),exponent-1))+trans.getItem(i).get_Amount());
             }
              else if(trans.getItem(i).AccType.equals("Debit")){
                  double exponent = Double.parseDouble(trans.getItem(i).get_Date().substring(0, 2));
                  updatedBal= (updatedBal*(Math.pow((1+ posRate),exponent-1))-trans.getItem(i).get_Amount());
                }
             }
            else
             {
                   if(trans.getItem(i).AccType.equals("Crebit")){
                   double exponent = Double.parseDouble(trans.getItem(i).get_Date().substring(0, 2));
                   updatedBal= (updatedBal*(Math.pow((1+ negRate),exponent-1))+trans.getItem(i).get_Amount());
             }
              else if(trans.getItem(i).AccType.equals("Debit")){
                  double exponent = Double.parseDouble(trans.getItem(i).get_Date().substring(0, 2));
                  updatedBal= (updatedBal*(Math.pow((1+ negRate),exponent-1))-trans.getItem(i).get_Amount());
                }
            }

              counter=counter.next;
        }

          this.set_balance(updatedBal);
    }


推荐答案

您的代码 trans.getItem(i).AccType.equals(Crebit)分两个地方。据推测应该是Cre d 它。如果交易项目的AccType字段的值使用正确的拼写,那么您的 if 块在计算利息时不会看到信用交易导致错误答案。

Your code has trans.getItem(i).AccType.equals("Crebit") in two places. Presumably that should be Credit. If the value of the AccType field of the transaction items is using the correct spelling, then your if blocks won't "see" the credit transactions when computing the interest and that could lead to a wrong answer.

这篇关于利息计算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆