Simple Interest Calculator Java Applet

Simple Interest Calculator Java Applet
A sample interest calculator, very basic in functionality, coded in Java and ready to be compiled and executed as a Java Applet.
1.import java.awt.*;
2.import java.awt.event.*;
3.import java.applet.*;
4.import java.text.NumberFormat;
5. 
6.public class InterestCalculator extends Applet implements ActionListener
7.{
8.        TextField textPresentVal = new TextField("0", 10);
9.        TextField textInterestRate = new TextField("0", 10);
10.        TextField textPeriods = new TextField("0", 10);
11.        Label lblPresentVal = new Label("Present Value");
12.        Label lblInterestRate = new Label("Interest Rate");
13.        Label lblPeriods = new Label("Number of Periods");
14.        Label lblFutureVal = new Label("Future Value:");
15.        Button btnOk = new Button("Calculate");
16. 
17.        public void init()
18.        {
19. 
20.                add(lblPresentVal);
21.                add(textPresentVal);
22.                add(lblInterestRate);
23.                add(textInterestRate);
24.                add(lblPeriods);
25.                add(textPeriods);
26.                add(lblFutureVal);
27.                add(btnOk);
28. 
29.                btnOk.addActionListener(this);
30.       }
31. 
32.        public void actionPerformed(ActionEvent evt)  
33.        {
34.            if (evt.getSource() == btnOk)
35.           {
36.                int PresentVal = Integer.parseInt(textPresentVal.getText());
37.                int InterestRate = Integer.parseInt(textInterestRate.getText());
38.                int Periods = Integer.parseInt(textPeriods.getText());
39.                double FutureVal = PresentVal * (Math.pow((1 + InterestRate), Periods));
40.               NumberFormat nf = NumberFormat.getCurrencyInstance();
41.                lblTotal.setText("Future Value: " + nf.format(FutureVal));
42. 
43.                repaint();
44.            }
45.        }
46.}
Nathan Pakovskie is an esteemed senior developer and educator in the tech community, best known for his contributions to Geekpedia.com. With a passion for coding and a knack for simplifying complex tech concepts, Nathan has authored several popular tutorials on C# programming, ranging from basic operations to advanced coding techniques. His articles, often characterized by clarity and precision, serve as invaluable resources for both novice and experienced programmers. Beyond his technical expertise, Nathan is an advocate for continuous learning and enjoys exploring emerging technologies in AI and software development. When he’s not coding or writing, Nathan engages in mentoring upcoming developers, emphasizing the importance of both technical skills and creative problem-solving in the ever-evolving world of technology. Specialties: C# Programming, Technical Writing, Software Development, AI Technologies, Educational Outreach

Leave a Reply

Your email address will not be published. Required fields are marked *

Back To Top