S
shannon
Hi,
Having problems trying to output my code, I figure that there is
something wrong with the for loops but can't get my head around it.
Would appreciate some help . thanks Shannon
import javax.swing.*;
import java.text.NumberFormat;
import java.util.Locale;
public class ScrollBar {
public static void main( String args[] ) {
{
double amount;
double principal = 1000.0;
//create NumberFormat for currency in US dollar Format
NumberFormat moneyFormat = NumberFormat.getCurrencyInstance(
Locale.US );
JTextArea outputArea = new JTextArea( 17, 50 );
JScrollPane scroller = new JScrollPane( outputArea );
String output = ( "Year\tAmount on
deposit\t5%\t6%\t7%\t8%\t9%\t10%\n ");
for ( double year = 1; year <= 10; year ++ ) {
//calculate amount of deposit for each of ten years
for ( double rate = .05; rate <= .10; rate += 0.01 ) {
//calculate interest rate
outputArea.setText( output );
//calculate new amount for specified year
amount = principal * Math.pow( 1.0 + rate, year);
//append one line of text to outputArea
outputArea.append( year + "\t" + principal + "\t" +
moneyFormat.format( amount ) +
"\t" + moneyFormat.format( amount
) +
"\t" + moneyFormat.format( amount
) +
"\t" + moneyFormat.format( amount
) +
"\t" + moneyFormat.format( amount
) +
"\t" + moneyFormat.format( amount
) + "\n" );
} //end for
}
JOptionPane.showMessageDialog( null, scroller, "Results",
JOptionPane.INFORMATION_MESSAGE );
System.exit( 0 );
}
}}
Having problems trying to output my code, I figure that there is
something wrong with the for loops but can't get my head around it.
Would appreciate some help . thanks Shannon
import javax.swing.*;
import java.text.NumberFormat;
import java.util.Locale;
public class ScrollBar {
public static void main( String args[] ) {
{
double amount;
double principal = 1000.0;
//create NumberFormat for currency in US dollar Format
NumberFormat moneyFormat = NumberFormat.getCurrencyInstance(
Locale.US );
JTextArea outputArea = new JTextArea( 17, 50 );
JScrollPane scroller = new JScrollPane( outputArea );
String output = ( "Year\tAmount on
deposit\t5%\t6%\t7%\t8%\t9%\t10%\n ");
for ( double year = 1; year <= 10; year ++ ) {
//calculate amount of deposit for each of ten years
for ( double rate = .05; rate <= .10; rate += 0.01 ) {
//calculate interest rate
outputArea.setText( output );
//calculate new amount for specified year
amount = principal * Math.pow( 1.0 + rate, year);
//append one line of text to outputArea
outputArea.append( year + "\t" + principal + "\t" +
moneyFormat.format( amount ) +
"\t" + moneyFormat.format( amount
) +
"\t" + moneyFormat.format( amount
) +
"\t" + moneyFormat.format( amount
) +
"\t" + moneyFormat.format( amount
) +
"\t" + moneyFormat.format( amount
) + "\n" );
} //end for
}
JOptionPane.showMessageDialog( null, scroller, "Results",
JOptionPane.INFORMATION_MESSAGE );
System.exit( 0 );
}
}}