Question 1 - Write a Java program to create an applet to find the simple interest on a given amount, rate of interest and duration. Use proper GUI components in your program.
Solution -
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class simple_interest_applet extends Applet implements ActionListener
{
float amt,roi,dur;
float interest;
Font f1 = new Font("Arial",Font.BOLD,20);
Label l1 = new Label("Amount");
Label l2 = new Label("Rate of Interest");
Label l3 = new Label("Duration (in years)");
TextField t1 = new TextField(20);
TextField t2 = new TextField(20);
TextField t3 = new TextField(20);
Button b1 = new Button("Calculate Interest");
public void init()
{
add(l1);
add(t1);
add(l2);
add(t2);
add(l3);
add(t3);
add(b1);
b1.addActionListener(this);
}
public void paint(Graphics g)
{
String str = "Interest = "+interest;
g.setFont(f1);
g.drawString(str,80,200);
}
public void actionPerformed(ActionEvent e)
{
amt = Float.parseFloat(t1.getText());
roi = Float.parseFloat(t2.getText());
dur = Float.parseFloat(t3.getText());
interest = (amt*roi*dur)/100;
repaint();
}
}
/*
<applet code="simple_interest_applet.class" width="330" height="350"></applet>*/
filename: simple_interest_applet.java
For compiling the file type this command in cmd: javac simple_interest_applet.javaFor execution of the file use this command: appletviewer simple_interest_applet.java
Note: Do not forgot to add this code
/*<applet code="simple_interest_applet.class" width="330" height="350"></applet>*/
in applet program otherwise applet program will not run;
Output:
if you have any doubt related to this post, you can ask in comment section and if you want solution of any previous year questions, please post that question in section we will try to solve that




