JAVA Project
JAVA Project
University of Delhi
PROJECT
Submitted to : Ms. Shikha Verma
Page | 2
Simple & Compound Interest Calculator
Location :
Page | 3
Formula Used :
Code :
package calculator;
import calc.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
Page | 4
public InterestCalc()
{
f1 = new JFrame("Simple & Compound Interest Calculator");
f1.setBounds(10,50,700,320);
//Adding Labels
JLabel label1 = new JLabel("Simple & Compound Interest
Calculator",JLabel.CENTER);
label1.setBounds(40,30,600,40);
Font fnt11 = new Font ("Arial",Font.BOLD,30);
label1.setFont(fnt11);
p1.add(label1);
Page | 5
//Creating Two Buttons
b1 = new JButton("Simple Interest");
b2 = new JButton("Compound Interest");
//Addding Buttons
p1.add(b1);
p1.add(b2);
//Add ActionListener
b1.addActionListener(this);
b2.addActionListener(this);
p1.setLayout(null);
f1.add(p1);
Page | 6
f1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f1.setResizable(false);
f1.setVisible(true);
f1.dispose();
Page | 7
public static void main(String args[])
{
Code:
package calc;
import calculator.InterestCalc;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public simpleCalc()
{
f2 = new JFrame("Simple Interest");
f2.setBounds(720,50,500,600);
Page | 9
formula.setBounds(40,80,410,70);
formula.setForeground(Color.BLUE);
formula.setBorder(BorderFactory.createLineBorder(Color.BLACK));
p2.add(formula);
//Adding Label
JLabel lbl2 = new JLabel("[ Please enter only Positive
Values. ]",JLabel.CENTER);
lbl2.setBounds(50,300,400,30);
lbl2.setForeground(Color.BLUE);
Font fnt3 = new Font ("Arial",Font.BOLD,15);
lbl2.setFont(fnt3);
Page | 11
p2.add(lbl2);
Page | 12
//Addding Buttons
p2.add(btn1);
p2.add(btn2);
p2.add(btn3);
//Add ActionListener
btn1.addActionListener(this);
btn2.addActionListener(this);
btn3.addActionListener(this);
p2.setLayout(null);
f2.add(p2);
f2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f2.setResizable(false);
f2.setVisible(true);
else
{
double p = Double.parseDouble(t1.getText());
double r = Double.parseDouble(t2.getText());
double t = Double.parseDouble(t3.getText());
double si = (p*r*t)/100;
String val = String.format("%.2f",si);
Page | 15
Code :
package calc;
import calculator.InterestCalc;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public compoundCalc()
{
f3 = new JFrame("Compound Interest");
f3.setBounds(720,50,500,600);
Page | 16
ImageIcon i = new ImageIcon("c.png");
f3.setIconImage(i.getImage());
formula1.setBorder(BorderFactory.createLineBorder(Color.BLACK));
p3.add(formula1);
Page | 18
//Addding Labels and TextFields
p3.add(l11);
p3.add(l22);
p3.add(l33);
p3.add(t11);
p3.add(t22);
p3.add(t33);
//Adding Label
JLabel lbl22 = new JLabel("[ Please enter only Positive
Values. ]",JLabel.CENTER);
lbl22.setBounds(50,300,400,30);
lbl22.setForeground(Color.BLUE);
Font font3 = new Font ("Arial",Font.BOLD,15);
lbl22.setFont(font3);
p3.add(lbl22);
//Addding Buttons
p3.add(btn11);
p3.add(btn22);
p3.add(btn33);
//Add ActionListener
btn11.addActionListener(this);
btn22.addActionListener(this);
Page | 20
btn33.addActionListener(this);
p3.setLayout(null);
f3.add(p3);
f3.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f3.setResizable(false);
f3.setVisible(true);
else
Page | 21
{
double p1 = Double.parseDouble(t11.getText());
double r1 = Double.parseDouble(t22.getText());
double t1 = Double.parseDouble(t33.getText());
Code :
import calculator.InterestCalc;
Page | 23
public class calculator
{
public static void main(String args[])
{
InterestCalc disp = new InterestCalc();
}
Output
Page | 24
1.When ‘Simple Interest’ button is clicked then ‘Simple Interest’
window for calculating Simple Interest will be opened.
Page | 25
Page | 26
If all or one of the values(P, R & When all the values (P, R & T) are
T) are not entered and ‘Calculate’ entered and ‘Calculate’ button is
button is clicked then ‘You must clicked then Simple Interest will be
enter all the values’ message will calculated and the result will be
appear. displayed.
Page | 27
When ‘Reset’ button is clicked When ‘Back’ button is clicked then
then all the values entered by the ‘Simple Interest’ window will be
the user and the result of the closed and the earlier window
earlier calculation will be ‘Simple & Compound Interest
erased. Calculator’ will be opened.
Page | 28
2.When ‘Compound Interest’ button is clicked then ‘Compound
Interest’ window for calculating Compound Interest will be opened.
Page | 29
If all or one of the values(P, R & When all the values (P, R & T) are
T) are not entered and ‘Calculate’ entered and ‘Calculate’ button is
button is clicked then ‘You must clicked then Compound Interest
enter all the values’ message will will be calculated and the result
appear. will be displayed.
Page | 30
When ‘Reset’ button is clicked When ‘Back’ button is clicked then
then all the values entered by the ‘Compound Interest’ window will
the user and the result of the be closed and the earlier window
earlier calculation will be ‘Simple & Compound Interest
erased. Calculator’ will be opened.
Page | 31
Conclus
ion :
The project ‘Simple and Compound Interest Calculator’ is
a simple application of Java. It takes the input (values of
'P', 'R' and 'T') from the user and calculates as per the
option selected by the user ('Simple interest' or
'Compound interest') and then displays the result with the
formula. This project is very suitable for calculating
simple and compound interest as the calculations are
highly accurate.
Page | 32