/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package calc_bank_interest;
/**
*
* @author
*/
import javax.swing.JOptionPane;
public class Calc_Bank_Interest
{
public static void main (String[] args)
{
double b, i; // balance (original deposit), interest rate
String s1 = "Course: CS-125 prog 1 with java 1, FALL 2013";
String s2 = "\nSample program by Prof, for HW chapter 4";
String s3 = "\n\nCalculate interest gain of a deposit with interest rate";
String s4 = "With interest rate compounded annually your account balance";
String s5 = "With interest rate compounded monthly your account balance";
String s6 = "With interest rate compounded daily your account balance";
String s7 = " in 10 years will be $";
String cont; //ask if continue for more calculation
JOptionPane.showMessageDialog (null, s1 + s2 + s3); //show program purpose
do
{
b = Double.parseDouble (JOptionPane.showInputDialog("Enter deposit amount: "));
i = Double.parseDouble (JOptionPane.showInputDialog("Enter interest rate(%): "));
double bY = b; //balance for interest compounded yearly
for (int y = 1; y <= 10; y++) //loop thru 10 years (y)
{ bY = bY * ( 1 + i/100 ); }
double bM = b; //balance for interest compounded monthly
for (int y = 1; y <= 10; y++) //loop thru 10 years
{
for (int m = 1; m <= 12; m++) //loop thru 12 months for each year
{ bM = bM * ( 1 + i/100/12); }
}
double bD = b; //balance for interest compounded daily
for (int y = 1; y <=10; y++) //loop thru 10 years
{
for(int d =1; d <= 365; d++) //loop thru 365 days for each year
{ bD = bD * ( 1 + i/100/365); }
}
JOptionPane.showMessageDialog (null, "Deposit amount= $" + b + " with interest rate: " + i + "%\n"
+ "\n" + s4 + s7 + String.format("%1.2f", bY) //bal by Yearly interest
+ "\n" + s5 + s7 + String.format("%1.2f", bM) //bal by Monthly interest
+ "\n" + s6 + s7 + String.format("%1.2f", bD)); //bal by Dailly interest
cont = JOptionPane.showInputDialog ("Continue to calculate of different amount? (Y/N)? ");
} while(cont.equalsIgnoreCase ("Y"));
JOptionPane.showMessageDialog ( null, "End of Job"); System.exit(0);
}
}