/** * 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); } }
I am a software engineer with a computational physics focus. The purpose of this blog is to showcase my ideas and works. I can create value and reduce costs for your company.