import java.util.*;

public class InterestCalculator
{
	// Program to compute the final total in a certificate of 
	// deposit after one year given the initial deposit, annual 
	// interest rate, and number of interest payments per year.

	public static void main(String[] args)
	{
		double deposit;
		double interestRate;
		int numPayments;
		double finalBalance;

		Scanner scan = new Scanner(System.in);

		System.out.print("Please input the initial deposit: ");
		deposit = scan.nextDouble();
		System.out.print("Please input the interest rate as a percentage: ");
		interestRate = scan.nextDouble();
		System.out.print("Please input the number of interest payments per year: ");
		numPayments = scan.nextInt();

		finalBalance = deposit * Math.pow(1 + (interestRate/100)/numPayments, numPayments);
		int totalCents = (int)(finalBalance * 100.0 + 0.5);  // round to nearest cent
		int dollars = totalCents / 100;     
		int tenths = totalCents / 10 % 10;  
		int hundredths = totalCents % 10;    

		displayBanner();
		System.out.println("Initial Deposit: $" + deposit);
		System.out.println("Interest Rate: " + interestRate + "%");
		System.out.println("Number of Interest Payments: " + numPayments);
		System.out.println("Final Amount: $" +
			dollars + "." + tenths + hundredths); 

		// Also: Look at the NumberFormat class
		// described in Chapter 3

	}
	
	public static void displayBanner()
	{
		System.out.println("**************************************");
		System.out.println("   TC BANK - CERTIFICATE OF DEPOSIT   ");
		System.out.println("**************************************");
	}

}
