20120129

Java Project #5 : Bank Investment


/**
 * BankInvestment computes the total money earned in an investment bank.
 * 
 * @author (Andrew Samuels) 
 * @version (02-04-2010)
 */
//importing Scanner from library
import java.util.Scanner;

public class BankInvestment
{
    public static void main(String[] args)
    {
    //create variables
    int initialInvestmentMoney; //initial investment money in dollars
    double interestRate; //interest rate in percentage
    int numberOfYears; //number of years of investment
    double totalMoneyEarnedDouble; //total money earned, double type, (converted to integer later)
    
    //Create Scanner
    Scanner keyboard = new Scanner(System.in);
        
    //capture initial investment from user
    System.out.print("Please enter initial investment (dollars): ");
    initialInvestmentMoney = keyboard.nextInt();
    
    //capture interest rate from user
    System.out.print("Please enter interest rate (percent): ");
    interestRate = keyboard.nextDouble();
    
    //capture numbers of years of investment from user
    System.out.print("Please enter years of investment (years): ");
    numberOfYears = keyboard.nextInt();
    
    //Calculate total money earned with formula p(1 + r/100)^n
    totalMoneyEarnedDouble = initialInvestmentMoney*(Math.pow(1 + interestRate/100, numberOfYears));
    
    //convert total money earned from double to integer
    int totalMoneyEarned = (int)totalMoneyEarnedDouble;
    
    //print total money earned
    System.out.println("The total money earned (dollars): " + totalMoneyEarned);
    }
}