简体   繁体   中英

Loan payment equations

I am trying to make a calculator for any type of fixed rate installment loans (mortgages included). Here is my following script for a basic calculator:

EditText myEdit = (EditText) findViewById(R.id.editBalance);
            String myEditValue = myEdit.getText().toString();
            double loanAmount = Double.parseDouble(myEditValue);

            EditText myEdit2 = (EditText) findViewById(R.id.editRate);
            String myEditValue2 = myEdit2.getText().toString();
            double interestRate = Double.parseDouble(myEditValue2);

            EditText myEdit3 = (EditText) findViewById(R.id.editTerm);
            String myEditValue3 = myEdit3.getText().toString();
            Double loanPeriod = Double.parseDouble(myEditValue3);

            double r = interestRate/1200;
            double r1 = Math.pow(r+1,loanPeriod);

            double editMnthlypmt = (double) ((r+(r/(r1-1))) * loanAmount);

            TextView textMnthlypmt = (TextView)findViewById(R.id.textMntlypmt);
            textMnthlypmt.setText("" + String.valueOf(editMnthlypmt));

I want to add a textEdit for additional monthly payments made; however, I have no idea how to calculate this, or adjust my equation for editMnthlypmt.

Any suggestions?

The equation has been completed and works beautifully.

        case R.id.calculate2:

        if (nicknameStr.length() > 0 && origBalStr.length() > 0 && myAPRStr.length() > 0 && origTermStr.length() > 0 && myPmtStr.length() > 0)
        {               

            double originalBalance = Double.parseDouble(origBalStr);
            double interestRate = Double.parseDouble(myAPRStr);
            double originalTerm = Double.parseDouble(origTermStr); 
            double remainingBalance = Double.parseDouble(strOutBal);

            double r = interestRate/1200;
            double r1 = Math.pow(r+1,originalTerm);

            double minPmt = (double) ((r+(r/(r1-1))) * originalBalance);
            DecimalFormat df = new DecimalFormat("#.##");      
            minPmt = Double.valueOf(df.format(minPmt));

            dispMinPmt.setText("" + String.valueOf(minPmt));


            double additionalPayment = Double.parseDouble(myPmtStr);
            double newPmt = minPmt + additionalPayment;

            dispNewPmt.setText("" + newPmt);

            double periodRate = r;

            double remTop = ((-1*Math.log(1-(periodRate) * (remainingBalance / newPmt))));
            double remBottom = (Math.log(1 + periodRate));
            double nRemaining = remTop / remBottom;

            double initialInt = (minPmt * nRemaining) - remainingBalance;
            double newInt = (newPmt * nRemaining) - remainingBalance;
            double amountSaved = initialInt - newInt;

        }
        else
        {
            Toast.makeText(getApplicationContext(), "Please complete all above fields", Toast.LENGTH_SHORT).show();
        }

        break;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM