统计信息

  • 访问数:11158
  • 博客数:142
  • 建立时间:2008-01-05
  • 更新时间:2008-05-21
我叫王超然,是一名电脑爱好者,现在在新加坡留学上高一.我立志成为一名电脑人才,愿意在这里与大家一同分享我玩转电脑的心得.O-level华文考了A-One哈哈!

P4Q5

2008-02-13 17:55:54

天气: 晴朗 心情: 郁闷

/*P4Q5
 * Name:Wang Chaoran
 * Description:5 (Comparing loans with various interest rates)
Write a program that lets the user enter the loan amount and loan period in number
of years and displays the monthly and total payments for each interest rate starting
from 5% to 8%, with an increment of 1/8. Suppose you enter the loan amount 10,000 for
five years; display a table as follows:

Loan Amount: 10000
Number of Years: 5
Interest Rate     Monthly Payment     Total Payment

5%                188.71              11322.74
5.125%            189.28              11357.13
5.25%             189.85              11391.59

...
7.85%             202.16              12129.97
8.0%              202.76              12165.83
*/
import java.util.Scanner;
public class P4Q5
{
  public static void main(String[]args)
  {
    Scanner scan = new Scanner(System.in);
    System.out.println("Please input the Loan Amount:");
    double loanAmount=scan.nextDouble();
    System.out.println("Please input the Number of Years:");
    double numberOfyears=scan.nextDouble();
    System.out.printf("%-18s%-18s%-18s","Interest Rate","Monthly Payment","Total Payment");
    System.out.println("\n");
    double interestRate=5,monthlyPayment=0,totalPayment;

    for(int i=1;i<= numberOfyears*12;i++)
    {
      totalPayment=10000*Math.pow((1+(interestRate/100)),4);
       System.out.printf("%-17f%1s%-18f%-18f",interestRate,"%",monthlyPayment,totalPayment);
    }
   
   
  
  }
}


加入收藏 编辑 审核

TAG: computing

我来说两句

OPEN

Powered by X-Space 1.2 © 2001-2006 Comsenz Technology Ltd