统计信息

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

p1Q9

2008-01-16 18:17:22

天气: 晴朗 心情: 高兴

/*p1Q9
 * Name:Wang Chaoran
 * Description:Write a program that reads in investment amount, annual interest rate,
 * and number of years, and displays the future investment value using the following formula:
*futureInvestmentValue = investmentAmount x (1 + monthlyInterestRate)numberOfYears*12
*For example, if you entered amount 1000, annual interest rate 3.25%, and number of years 1, the future investment value is 1032.98.
*Hint: Use the Math.pow(a, b) method to compute a raised to the power of b.
 */

import java.util.Scanner;
import java.text.DecimalFormat;
class p1Q9
{
  public static void main(String[] args)
  {
    double investmentAmount, annualInterestRate, numberOfYears, monthlyInterestRate, futureInvestmentValue;
    System.out.println("Please in put the investment amount: ");
    //Step One:Create a scanner
    Scanner scan = new Scanner(System.in);
    //Step Two:Read in investmentAmount, monthlyInterestRate and numberOfYears
    investmentAmount = scan.nextDouble();
    System.out.println("Please in put the annual interest rate: ");
    annualInterestRate = scan.nextDouble();
    System.out.println("Please in put the number of years: ");
    numberOfYears = scan.nextDouble();
    //Step Three: Calculate future investment value
    monthlyInterestRate = annualInterestRate /12;    
    futureInvestmentValue = investmentAmount * Math.pow((1 + monthlyInterestRate),numberOfYears*12);
   DecimalFormat df = new DecimalFormat("0.00");
   String output = df.format(futureInvestmentValue);
   /*altenate method: futureInvestmentValue*1000 =futureInvestmentValue;
    if ((futureInvestmentValue % 10)>=5)
    {
      futureInvestmentValue =Math.ceil(futureInvestmentValue / 10);
    }
    else futureInvestmentValue = Math.rint(futureInvestmentValue/10);
    futureInvestmentValue = futureInvestmentValue/100;*/
    //refer to 5.9. The Math Class
   //Step Four: Display future investment rate
    System.out.println("The future investment value is: "+output);
  
  }
}


加入收藏 编辑 审核

TAG: computing

我来说两句

OPEN

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