-2

このプログラムで分割払いを正しく表示できません。助けてください。ありがとうございます......

package Loops;

import java.util.Scanner;

/**
 *
 * 
 */
public class program {

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        //variabled decleared
        double rate;
        double payment;
        //input
        System.out.print("Enter Loan Amount:");
        double principal = input.nextDouble();
        System.out.print("Enter Annual Interest:");
        double interest = input.nextDouble();
        System.out.print("Total payments per year:");//12=monthly,4= quartely,2=semi-annually and 1=annually
        double period = input.nextDouble();
        System.out.print("Enter Loan Length :");
        int length = input.nextInt();

        //proces
        double n = period * length;
        rate = interest / 100;
        double monthly_rate = rate / period;
        payment = principal * (principal * (monthly_rate * Math.pow((1 + monthly_rate), n)));

        System.out.printf("Your Monthly sum is %.2f", payment);


    }
}
4

2 に答える 2

1
principal = 50000; //Redacted. Eating my words.

period = 4;
length = 4;
n = 16;

rate = 0.085;
monthly_rate = 0.085 / 16 = 0.0053125;

payment = 50000 * 50000 * 0.0053125 * (1 + 0.0053125) ^ 16;
        = 2.5x10^9 * 0.0053125 * 1.088;
        = Something remainingly massive

Basically... your formula is wrong. Wouldn't you need to divide by the power quotient? Where is your source on that formula?

payment = principal * (rate + (rate / ( Math.pow(1 + rate, n) - 1) ) );

Source

Example:

payment = 50000*(0.085+(0.085/(1.085^16-1)))
= 5830.68
于 2012-11-14T20:34:56.400 に答える
0

あなたの式のためにこれを試してください:

//this is how much a monthly payment is
payment = (rate + (rate / ((Math.pow(1 + rate), n) -1)) * principal

これは、数式の最初のGoogle検索結果の1つに基づいています。間違っている場合は、結果と予想される回答を投稿してください。

方程式には分母があるはずだと上で述べたように、あなたの公式はちょうどずれていると私はかなり確信しています。

You can use r* Math.pow ((1+r),n) to calculate the numerator and part of the denominator

于 2012-11-14T21:15:39.363 に答える