// Example of a static (or class) method, and parameter passing. /* Compute the value of a bank account after a specified period of time assuming that the initial balance and the annual interest rate are given, and the interest is compounded monthly. */ import java.util.*; class BankAcc { public static final int numberOfMonths = 12; public static void main (String[] args) { float balance, rate; int years; Scanner scan = new Scanner (System.in); System.out.print ("Enter initial balance: "); System.out.flush (); balance = scan.nextFloat(); System.out.print ("Enter annual interest rate (in %): "); System.out.flush (); rate = scan.nextFloat(); System.out.print ("Enter period of time (in years): "); System.out.flush (); years = scan.nextInt(); float newBalance = computeValue(rate, balance, years); if (newBalance != 0) { System.out.print ("For initial balance of $" + balance + " and "); System.out.println ("annual interest of " + rate + "%, "); System.out.print ("the new balanace after " + years + " years will be $"); System.out.println (newBalance); } else System.out.println (); } /* Computes the value of an investment and return the balance after the specified period, years. */ public static float computeValue (float rate, float balance, int years) { if (years < 0 || rate < 0 || balance < 0) { System.out.println ("Incorrect input. Try again with correct input data."); return 0; } else { float b = (float) (balance * Math.pow(1 + rate/(numberOfMonths*100), numberOfMonths*years)); return b; } } }