Cannot output Results
Hi,
Having problems outputting the following text. I had the text outputting before i added the scroll bar functionality, I can't figure out where i went wrong. Maybe someone can help. thanks in advance. 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 ");
//calculate amount of deposit for each of ten years
for ( int year = 1; year <= 10; year ++ ) {
//calculate interest rate
for ( int rate = 5; rate <= 10; rate ++ ) {
//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" + 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
}
outputArea.setText( output );
JOptionPane.showMessageDialog( null, scroller, "Results Table", JOptionPane.INFORMATION_MESSAGE );
System.exit( 0 );
}
}}
[2175 byte] By [
ShanD] at [2007-11-11 7:54:52]

# 4 Re: Cannot output Results
ok, have been working on this and i think its nearly there except that all my years and interest rate results are going down in one line instead of the years down and the rates across. The result figures are now right but the display isnt.
Sorry the code is a bit messy have been blocking out stuff and putting it back in while trying to get this right.
I really appreciate the help.
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\n\t " + "deposit\t5%\t6%\t7%\t8%\t9%\t10%\n ");
outputArea.setText( output );
for ( double rate = .05; rate <= .10; rate += 0.01 ) {
for ( int year = 1; year <= 10; year ++ ) {
//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 ) + "\n" );
// "\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 );
}
}}
ShanD at 2007-11-11 22:40:08 >
