/** * @(#)Laina.java * * Laina Applet application * * @author * @version 1.00 2012/1/11 */ import java.applet.*; import java.awt.*; import java.awt.event.*; public class Laina extends Applet implements ActionListener { TextField tpo, tai, tkk; Button bann, btas; int ai, i, a; double po, kk, ly, ko, ann,r; public void init () { add(tpo = new TextField("150000")); add(tai = new TextField("10")); add(tkk = new TextField("5")); add(bann = new Button("Annuiteetti")); add(btas = new Button("Tasaerä")); bann.addActionListener(this); btas.addActionListener(this); } public void paint(Graphics g) { g.drawString("Pääoma:",5,33); g.drawString("Aika:",5,53); g.drawString("Korkokanta:",5,73); g.drawString("Annuiteetti: "+Math.round(ann),5,93); tpo.reshape(70, 20, 70, 20); tai.reshape(70, 40, 70, 20); tkk.reshape(70, 60, 70, 20); bann.reshape(70, 120, 70, 30); btas.reshape(70, 150, 70, 30); g.drawString("Vuosi",150,13); g.drawString("Lyhennys",200,13); g.drawString("Korko",300,13); g.drawString("Pääoma",400,13); for ( i = 1 ; i <= ai ; i++ ) { g.drawString(""+i,150,13+i*15); g.drawString(""+Math.round(ly),200,13+i*15); g.drawString(""+Math.round(ko),300,13+i*15); g.drawString(""+Math.round(po),400,13+i*15); if (a==0) { po=po-ly; ko=kk*po/100; ly=ann-ko; } if (a==1){ po=po-ly; ko=kk*po/100; } } } public void actionPerformed(ActionEvent e) { if (e.getActionCommand().equals("Annuiteetti")){ po=Double.valueOf(tpo.getText()); ai=Integer.valueOf(tai.getText()); kk=Double.valueOf(tkk.getText()); r = ( 100 + kk ) / 100; ann=po*(Math.pow(r,ai)*(r-1))/(Math.pow(r,ai)-1); ko=kk*po/100; ly=ann-ko; a=0; repaint(); } if (e.getActionCommand().equals("Tasaerä")){ ann=0; po=Double.valueOf(tpo.getText()); ai=Integer.valueOf(tai.getText()); kk=Double.valueOf(tkk.getText()); ko=kk*po/100; ly=po/ai; a=1; repaint(); } } }