Java复合兴趣计划(SOLVED)

时间:2020-10-02 23:36:14

标签: java math parameters java.util.scanner

我想知道是否有人可以帮助我编写代码,因为我不知道它可能有什么问题。该计划的整体思路是从本质上确定学生贷款的复利应为多少。输入必须由我已经正确编码的用户给出。该程序需要在用户输入的以下参数上运行:$ 25000贷款,为期4年,按6.25%的利息按月计息。

程序输出:

程序应要求用户输入使用的每个参数

程序应使用参数调用方法

(R应该由用户输入一个百分比并由程序转换)

最终输出应为:这一次我欠我的贷款利息为:(此处为计算值)

我基本上希望它做的是计算复利,就像我上面所说的,它应该是7000,但是我得到了1.3735924645205525E13。所以出了点问题,但我不确定。我可能错过了某些事情或做错了一些我不知道的事情,这就是为什么我毕竟在这里。

任何帮助将不胜感激。另外,对于我在这里是新手,缺乏格式表示抱歉。如果有任何不清楚或令人困惑的地方,请随时提出。谢谢。


代码:

    import java.util.Scanner;

    public static void main(String[] args) {
        double P = 0.0;
        double R = 0.0;
        double t = 0.0;
        double n = 0.0;
        double CI = 0.0;
        double CL = 0.0;
        Scanner A = new Scanner(System.in); 
    
        System.out.print("Please enter in the pricipal amount: ");
        P = A.nextDouble();
        System.out.print("Please enter the annual interest rate: ");
        R = A.nextDouble();
        System.out.print("Please enter the time period: ");
        t = A.nextDouble();
        System.out.print("Please enter the amount of times the interest is coumpounded a year: ");
        n = A.nextDouble();
    
        CI = Math.pow((1 + (R / n)), (n * t));
        CL = ((P * CI) - P);
    
        System.out.println(" ");
        System.out.println("The interest I would owe on my loan at this time is: " + CL);   
    }
}

结果:

请输入本金:25000

请输入年利率:6.25

请输入时间段:4

请输入一年的利息计算次数:12

这时我欠贷款的利息是:1.3735924645205525E13

0 个答案:

没有答案
相关问题