Various Interest Rates



hi all,

Working on this compound Interest Program and want to repeat the
program for 10 different interest rates, I think i should be using a
loop but not quite sure how to go about it. The following is what i
have so far.

Cheers
Shannon

____________________________________________________________________

//Java Packages

import java.text.NumberFormat; // class for numeric formatting
import java.util.Locale; // class for country-specific information

import javax.swing.JOptionPane;
import javax.swing.JTextArea;


public class CompoundInterestProgram {

public static void main( String args[] )
{

double amount; //amount on deposit at end of each year
double principal = 20000.0; // initial amount before interest



//create NumberFormat for currency in US dollar format
NumberFormat moneyFormat = NumberFormat.getCurrencyInstance( Locale.US
);

// create JTextArea to display output
JTextArea outputTextArea = new JTextArea();

// set first line of text in outputTextArea
outputTextArea.setText( "Year\tAmount on deposit\n" );

// calculate amount of deposit for each of ten years
for ( int year = 1; year <= 10; year ++ ) {

//
for ( int rate = 1; rate <= 10; rate ++)

// calculate new amount for specified year
amount = principal * Math.pow( 1.0 + rate, year );

// append one line of text to outputTextAea
outputTextArea.append( year + "\t" + moneyFormat.format( amount
) + "\n" );

}// end for

// display results

JOptionPane.showMessageDialog( null, outputTextArea, "Compound
Interest", JOptionPane.INFORMATION_MESSAGE );

System.exit ( 0 ); // terminates the application

} // end main
} // end class Interest

.



Relevant Pages

  • More useful stuff in 11g
    ... A new pragma that inlines subprogram calls ... Compound table triggers ... The ability, within a loop, to continue processing at the top of the loop ...
    (comp.databases.oracle.server)
  • Re: Towers of Hanoi Problem
    ... Which reference? ... According to the CLHS, at least one compound ... form must follow "finally" in LOOP. ...
    (comp.lang.lisp)
  • Re: Too Many if Statements?
    ... The problem is writing a compound ... of the loop to the code that follows after the loop). ... Until the jump limit ...
    (comp.lang.python)