
import java.text.NumberFormat;
import javax.swing.JOptionPane;


/**
 * COP2210 Example
 * @author Bill Kraynek
 */
public class ClassExampleTwo {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        double amount = 100;
        double rate = .03;
        int years = 25;
        NumberFormat currency = NumberFormat.getCurrencyInstance();
        String displayString = "The amount is " + currency.format(amount) + "\n";
        displayString = displayString + "The rate is " + rate + "\n";
        displayString = displayString + "The years is " + years + "\n";
        double total = amount * (1 + rate);
        displayString += "The total after one year is " + currency.format(total) + "\n";
        total = amount * Math.pow(1 + rate, years);
        displayString += "The total after " + years + " years is " + currency.format(total) + "\n";
        total = amount * Math.pow(1 + rate / 12, 12);
        displayString += "The total after one year compounding monthly is " + currency.format(total) + "\n";
        total = amount * Math.pow(1 + rate / 12, years * 12);
        displayString += "The total after " + years + " years compounding monthly is " + currency.format(total) + "\n";
        total = amount * Math.pow(1 + rate / 365, 365);
        displayString += "The total after one year compounding daily is " + currency.format(total) + "\n";
        total = amount * Math.pow(1 + rate / 365, years * 365);
        displayString += "The total after " + years + " years compounding daily is " + currency.format(total) + "\n";
        total = amount * Math.pow(1 + rate, 1);
        total += amount * Math.pow(1 + rate, 2);
        total += amount * Math.pow(1 + rate, 3);
        total += amount * Math.pow(1 + rate, 4);
        total += amount * Math.pow(1 + rate, 5);
        displayString += "The total after investing the amount each year for 5 years is " + currency.format(total) + "\n";
        total = 0.0;
        int year = 0;
        while( true) {
            if( year == years ) break;
            total = (total + amount) * (1.0 + rate);
            year = year + 1;
        }// end while
        displayString += "The total after investing the amount each year for " + years + " years is " + currency.format(total) + "\n";
        JOptionPane.showMessageDialog(null, displayString);
    }

}

