答案家

 找回密码
 立即注册
查看: 1234|回复: 0

java编程财务应用程序:显示分期还贷时间表

[复制链接]

1万

主题

1万

帖子

80万

积分

校长

Rank: 9Rank: 9Rank: 9

积分
808992
发表于 2016-12-24 16:17:32 | 显示全部楼层 |阅读模式
package nameyu;
import java.util.Scanner;public class Test {
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner input=new Scanner(System.in);
        System.out.print("Loan Amount:");
        double loan=input.nextDouble();
        System.out.print("Numeber of years:");
        int years =input.nextInt();
        System.out.print("Annual Interest Rate:");
        double InterestRate=input.nextDouble();
        double MonthlyPayment=loan*(InterestRate/1200)/(1-1/Math.pow(1+InterestRate/1200, years*12));
        double TotalPayment=MonthlyPayment*years*12;
        System.out.printf("%-4.2f%s%-4.2f%n",MonthlyPayment,"  ",TotalPayment);
        System.out.println();
        System.out.println("Payment#"+"\t"+"Interest"+"\t\t\t"+"Principal"+"\t\t\t"+"Balance");
        double balance=loan;
        for(int i=1;i<=years*12;i++){
            double  Interest=(InterestRate/1200)*balance;
            double principal=MonthlyPayment-Interest;
            balance=balance-principal;
            System.out.println(i+"\t\t"+Interest+"\t\t"+principal+"\t\t"+balance);
        }
    }
}

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

CopyRight(c)2016 www.daanjia.com All Rights Reserved. 本站部份资源由网友发布上传提供,如果侵犯了您的版权,请来信告知,我们将在5个工作日内处理。
快速回复 返回顶部 返回列表