IFSC based bank detail finder using core java

Project Structure:

Add following maven dependency in pom.xml


  <dependency>
		<groupId>com.google.code.gson</groupId>
		<artifactId>gson</artifactId>
		<version>2.8.5</version>
   </dependency>

Bank.java


package com.example.model;

public class Bank {
	private String DISTRICT;
	private Boolean RTGS;
	private String SWIFT;
	private Boolean UPI;
	private String CONTACT;
	private Boolean NEFT;
	private String CITY1;
	private String MICR;
	private Boolean IMPS;
	private String PHONE;
	private String ADDRESS;
	private String BRANCH;
	private String CITY2;
	private String CITY;
	private String STATE;
	private String CENTRE;
	private String BANK;
	private String BANKCODE;
	private String IFSC;

	public String getDISTRICT() {
		return DISTRICT;
	}

	public void setDISTRICT(String dISTRICT) {
		DISTRICT = dISTRICT;
	}

	public Boolean getRTGS() {
		return RTGS;
	}

	public void setRTGS(Boolean rTGS) {
		RTGS = rTGS;
	}

	public String getSWIFT() {
		return SWIFT;
	}

	public void setSWIFT(String sWIFT) {
		SWIFT = sWIFT;
	}

	public Boolean getUPI() {
		return UPI;
	}

	public void setUPI(Boolean uPI) {
		UPI = uPI;
	}

	public String getCONTACT() {
		return CONTACT;
	}

	public void setCONTACT(String cONTACT) {
		CONTACT = cONTACT;
	}

	public Boolean getNEFT() {
		return NEFT;
	}

	public void setNEFT(Boolean nEFT) {
		NEFT = nEFT;
	}

	public String getCITY1() {
		return CITY1;
	}

	public void setCITY1(String cITY1) {
		CITY1 = cITY1;
	}

	public String getMICR() {
		return MICR;
	}

	public void setMICR(String mICR) {
		MICR = mICR;
	}

	public Boolean getIMPS() {
		return IMPS;
	}

	public void setIMPS(Boolean iMPS) {
		IMPS = iMPS;
	}

	public String getPHONE() {
		return PHONE;
	}

	public void setPHONE(String pHONE) {
		PHONE = pHONE;
	}

	public String getADDRESS() {
		return ADDRESS;
	}

	public void setADDRESS(String aDDRESS) {
		ADDRESS = aDDRESS;
	}

	public String getBRANCH() {
		return BRANCH;
	}

	public void setBRANCH(String bRANCH) {
		BRANCH = bRANCH;
	}

	public String getCITY2() {
		return CITY2;
	}

	public void setCITY2(String cITY2) {
		CITY2 = cITY2;
	}

	public String getCITY() {
		return CITY;
	}

	public void setCITY(String cITY) {
		CITY = cITY;
	}

	public String getSTATE() {
		return STATE;
	}

	public void setSTATE(String sTATE) {
		STATE = sTATE;
	}

	public String getCENTRE() {
		return CENTRE;
	}

	public void setCENTRE(String cENTRE) {
		CENTRE = cENTRE;
	}

	public String getBANK() {
		return BANK;
	}

	public void setBANK(String bANK) {
		BANK = bANK;
	}

	public String getBANKCODE() {
		return BANKCODE;
	}

	public void setBANKCODE(String bANKCODE) {
		BANKCODE = bANKCODE;
	}

	public String getIFSC() {
		return IFSC;
	}

	public void setIFSC(String iFSC) {
		IFSC = iFSC;
	}

}
  

BankService.java


package com.example.service;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

import com.example.model.Bank;
import com.google.gson.Gson;

public class BankService {

	public Bank getBankDetailAPi(String ifsc) {
		try {
			String api = "https://ifsc.razorpay.com/" + ifsc;
			URL url = new URL(api);
			HttpURLConnection hr = (HttpURLConnection) url.openConnection();
			InputStream inputStream = hr.getInputStream();
			BufferedReader br = new BufferedReader(new InputStreamReader(inputStream));
			String line = br.readLine();
			StringBuffer sb = new StringBuffer();
			while (line != null) {
				sb.append(line).append("\n");
				line = br.readLine();
			}
			System.out.println(sb.toString());
			return new Gson().fromJson(sb.toString(), Bank.class);

		} catch (Exception e) {
			System.out.println(e);
		}
		return null;
	}

}
  

MainPage.java


package com.example.ui;

import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;

import com.example.model.Bank;
import com.example.service.BankService;

public class MainPage {
	private BankService bankService = new BankService();

	public MainPage() {
		JFrame frame = new JFrame("IFSC BASED BANK DETAIL FINDER");
		frame.setSize(600, 500);
		frame.setLocationRelativeTo(null);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		JPanel panel = new JPanel();
		panel.setBackground(new Color(10, 56, 67));
		panel.setLayout(null);

		JTextField textField = new JTextField();
		textField.setBounds(100, 100, 300, 35);
		panel.add(textField);

		JButton button = new JButton("Search");
		button.setBounds(410, 100, 100, 35);
		panel.add(button);

		JTextArea textArea = new JTextArea();
		textArea.setFont(new Font("", Font.BOLD, 12));
		JScrollPane jp = new JScrollPane(textArea);
		jp.setBounds(100, 160, 410, 200);
		panel.add(jp);

		frame.add(panel);

		frame.setVisible(true);

		button.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				Bank bank = bankService.getBankDetailAPi(textField.getText());
				if (bank != null) {
					String result = "Bank Name : " + bank.getBANK() + "\n" + "Bank Address : " + bank.getADDRESS()
							+ "\n" + "Bank City : " + bank.getCITY() + "\n" + "Bank Branch : " + bank.getBRANCH() + "\n"
							+ "Bank District : " + bank.getDISTRICT() + "\n" + "Bank State : " + bank.getSTATE() + "\n";
					textArea.setText(result);
				} else {
					textArea.setText("Please check your IFSC code");
				}

			}
		});
	}

	public static void main(String[] args) {
		new MainPage();
	}
}
  

Output Screens:



No comments: