source code help

From: bugns (bugns_at_msn.com)
Date: 01/30/05


Date: 29 Jan 2005 19:08:32 -0800

import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import java.lang.Math.*;
import java.text.DecimalFormat;

public class Investment extends Applet implements ActionListener {
Label l1,l2,l3;
TextField t1,t2,t3;
Button btn;
int xpos,ypos;
double deposit,year,cashback;
double A1,A2,A3,A4,A5,A6,A7,A8,A9,A10;
DecimalFormat df = new DecimalFormat("###,###,###,###.00");

public void init() {
Panel p = new Panel( );
Panel p1 = new Panel( );
l1= new Label("Enter the initial amount of Deposit: ");
l2=new Label("Enter the no. of years to deposit: ");
l3=new Label("Enter the amount of Cashback for each year: ");
t1=new TextField(10) ;
t2=new TextField(10) ;
t3=new TextField(10) ;
btn=new Button("Calculate Amount: ");
p.setLayout( new GridLayout(3,2,5,5) );
p.add(l1);
p.add(t1);
p.add(l2);
p.add(t2);
p.add(l3);
p.add(t3);
p1.setLayout( new BorderLayout(5,5));
p1.add( "North", p);
p1.add( "South", btn);
add( p1);
btn.addActionListener(this);
}

public void actionPerformed(ActionEvent event) {
deposit= Double.parseDouble(t1.getText());
year= Double.parseDouble(t2.getText());
cashback= Double.parseDouble(t3.getText());
if (year>=1)
A1=deposit*Math.pow(1.015,1 )-cashback;
if (year>=2)
A2=A1*Math.pow(1.015,2 )-cashback;
if (year>=3)
A3=A2*Math.pow(1.015,3)-cashback;
if (year>=4)
A4=A3*Math.pow(1.02,4 )-cashback;
if (year>=5)
A5=A4*Math.pow(1.02,5 )-cashback;
if (year>=6)
A6=A5*Math.pow(1.02,6 )-cashback;
if (year>=7)
A7=A6*Math.pow(1.025,7 )-cashback;
if (year>=8)
A8=A7*Math.pow(1.025,8 )-cashback;
if (year>=9)
A9=A8*Math.pow(1.025,9 )-cashback;
if (year>=10)
A10=A9*Math.pow(1.025,10)-cashback;
repaint();
}

public void paint(Graphics g) {

g.drawString("Years ", 50, 300 );
g.drawString("Amount to deposit", 150, 300 );
if ((year<=0)||(deposit<=0)||(cashback<0))
g.drawString("Please enter appropriate values ", 50, 200 );
if ((year>=1)&&(deposit>0)&&(cashback>=0)&&(A1>0))
g.drawString(""+df.format(A1), 150, 315 );
if ((year>=2)&&(deposit>0)&&(cashback>=0)&&(A2>0))
g.drawString(""+df.format(A2), 150, 330 );
if ((year>=3)&&(deposit>0)&&(cashback>=0)&&(A3>0))
g.drawString(""+df.format(A3), 150, 345);
if ((year>=4)&&(deposit>0)&&(cashback>=0)&&(A4>0))
g.drawString(""+df.format(A4), 150, 360);
if ((year>=5)&&(deposit>0)&&(cashback>=0)&&(A5>0))
g.drawString(""+df.format(A5), 150, 375);
if ((year>=6)&&(deposit>0)&&(cashback>=0)&&(A6>0))
g.drawString(""+df.format(A6), 150, 390);
if ((year>=7)&&(deposit>0)&&(cashback>=0)&&(A7>0))
g.drawString(""+df.format(A7), 150, 405);
if ((year>=8)&&(deposit>0)&&(cashback>=0)&&(A8>0))
g.drawString(""+df.format(A8), 150, 420);
if ((year>=9)&&(deposit>0)&&(cashback>=0)&&(A9>0))
g.drawString(""+df.format(A9), 150, 435);
if ((year>=10)&&(deposit>0)&&(cashback>0)&&(A10>0))
g.drawString(""+df.format(A10), 150, 450);

int xpos = 50, ypos = 315;
for ( year = 1; year <= 10; year++){
g.drawString(""+year,xpos,ypos);
xpos = xpos ;
ypos = ypos+15 ;
}
}
}

How do i make the result to display more than year 10 without typing
the same old text and that the year column will only display according
to input and not as above.

THANX

java newbie


Quantcast