JAVA Project
JAVA Project
University of Delhi
PROJECT
Submitted to : Ms. Shikha Verma
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.*;
Page | 8
JLabel formula,res;
JLabel l1,l2,l3;
JTextField t1,t2,t3;
JButton btn1,btn2,btn3;
public simpleCalc()
{
f2 = new JFrame("Simple Interest");
f2.setBounds(720,50,500,600);
Page | 9
formula.setFont(fnt1);
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);
Page | 11
lbl2.setFont(fnt3);
p2.add(lbl2);
Page | 12
btn3.setFont(fnt4);
//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);
Page | 13
JButton b = (JButton)e.getSource();
if(b == btn1)
{
if(t1.getText().equals("") || t2.getText().equals("")
|| t3.getText().equals(""))
{
JOptionPane.showMessageDialog(f2,"You must enter all the
values.","Error Message",JOptionPane.INFORMATION_MESSAGE);
}
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
DIRECTORY NAME : calc
FILE NAME : compoundCalc.java
Code :
package calc;
import calculator.InterestCalc;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
Page | 16
public compoundCalc()
{
f3 = new JFrame("Compound Interest");
f3.setBounds(720,50,500,600);
formula1.setBorder(BorderFactory.createLineBorder(Color.BLACK));
p3.add(formula1);
Page | 17
//Creating Three Labels
l11 = new JLabel("Principal in Rs. (P): ");
l22 = new JLabel("Rate in % (R) : ");
l33 = new JLabel("Time in years (T) : ");
Page | 18
l22.setFont(font2);
l33.setFont(font2);
t11.setFont(font2);
t22.setFont(font2);
t33.setFont(font2);
//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);
Page | 20
p3.add(btn33);
//Add ActionListener
btn11.addActionListener(this);
btn22.addActionListener(this);
btn33.addActionListener(this);
p3.setLayout(null);
f3.add(p3);
f3.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f3.setResizable(false);
f3.setVisible(true);
Page | 21
{
JOptionPane.showMessageDialog(f3,"You must enter all the
values.","Error Message",JOptionPane.INFORMATION_MESSAGE);
}
else
{
double p1 = Double.parseDouble(t11.getText());
double r1 = Double.parseDouble(t22.getText());
double t1 = Double.parseDouble(t33.getText());
Page | 23
FILE NAME : calculator.java
Code :
import calculator.InterestCalc;
Page | 24
Page | 25
1.When ‘Simple Interest’ button is clicked then ‘Simple Interest’ window
for calculating Simple Interest will be opened.
Page | 26
If all or one of the values(P, R & T) When all the values (P, R & T) are
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 ‘Simple
earlier calculation will be & Compound Interest Calculator’ will
erased. 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 & T) When all the values (P, R & T) are
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 will
appear. 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
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