You are on page 1of 7

Name:Mohit Saini

Roll No:20
Class:MCA(M) 4th Sem

Source Code:-EMI.java
package emi_calculator;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
public class EMI extends JFrame implements ActionListener {
JComboBox type_loan;
JLabel t1,t2,t3;
JTextField txt1,txt2;
JButton b1;
EMI()
{

setLayout(new FlowLayout());
t1=new JLabel("Loan Amount");
txt1=new JTextField(10);

t2=new JLabel("Tenure(in month)");


txt2=new JTextField(10);
String[] type={"four wheeler","two
wheeler","home","education"};
t3=new JLabel("Type of Loan");
b1=new JButton("calculate");
type_loan=new JComboBox(type);
add(t1); add(txt1);
add(t2); add(txt2);
add(t3);add(type_loan);
add(b1);
b1.addActionListener(this);
}
public static void main(String[] args)
{
EMI z=new EMI();
z.setTitle("EMI Calculator");
z.setBounds(100,100,250,300);
z.setVisible(true);
z.setResizable(false);
z.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

public void actionPerformed(ActionEvent e) {


String amount =txt1.getText();
String time=txt2.getText();
String rate =(String) type_loan.getSelectedItem();

try
{
String ra="";
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException ex) {

Logger.getLogger(EMI.class.getName()).log(Level.SEVERE, null,
ex);
}
Connection
conn=DriverManager.getConnection("jdbc:mysql://localhost:33
06/loan","root","12345");
Statement s=conn.createStatement();
ResultSet rs=s.executeQuery("Select rate from loan
where type='"+rate+"'");

while(rs.next())
{
ra=rs.getString("rate");
}
double p=Double.parseDouble(amount);
double t=Double.parseDouble(time);
double r=Double.parseDouble(ra);
double emi = (p*r*((1 + r)*t))/((1 + r)*t - 1);
JOptionPane.showMessageDialog(null, "EMI="+emi);
}
catch(SQLException e1)
{
e1.printStackTrace();
}

}
Output:-
Database:-
Database name:- loan
Table name:- type_loan

You might also like