Friday, February 1, 2019

Simple Banking Transaction BlueJ Program

This is a BlueJ program on simple banking transactions. 

Name, Account Number  and Initial Balance are taken and minimum balance amount is Rs. 3000.
Transactions (deposit and withdrawal) continues till user stops it and loan can be sanctioned.

import java.io.*;

class Bank

{

String name,acno;
double amount,loan;
String date1;
/* 'name' to hold name, 'amount' will hold initial amount, 'acno' will hold account number, 'loan' will hold the loan taken (if any) 'date1' holds the dates of transactions */

BufferedReader br;

Bank()
{
br=new BufferedReader(new InputStreamReader(System.in));
}

private void initial()throws IOException
{
System.out.println("Date of opening Account(dd/mm/yyyy):");
date1=br.readLine().toUpperCase();

System.out.println("Name with Surname:");
name=br.readLine().toUpperCase();

System.out.println("A/c No.:");
acno=br.readLine().trim();

System.out.println("Initial Amount:");
amount=Double.parseDouble(br.readLine());
}

private void transaction()throws IOException

{

double amount1; 
String dep1;

/* 'amount1' will hold the transaction amount, 'dep1' will hold mode of transaction,  */

System.out.println("Date of transaction (dd/mm/yyyy):");
date1=br.readLine().trim();

System.out.println("Enter the transaction type(d for deposit/w for withdrawal):");
dep1=br.readLine().trim().toLowerCase();

System.out.println("Enter the amount:");
amount1=Double.parseDouble(br.readLine());

if(dep1.equals("w"))
{
if(amount-amount1 < 0)<3000 font="">
{
System.out.println("Insufficient Balance");
}

else
{
amount=amount-amount1;
}
}

else if(dep1.equals("d"))
{
amount=amount+amount1;
}
}

private void loan()throws IOException
{
double amount1; 
System.out.println("Date of taking loan (dd/mm/yyyy):");
date1=br.readLine().trim();

System.out.println("Enter the loan amount:");
amount1=Double.parseDouble(br.readLine());

if(amount1>amount-3000)
{
System.out.println("Insufficient Balance, Not possible to grant loan of Rs."+ amount1);
}

else
{
amount=amount-amount1;
}
}

private void display()

{
System.out.println("\n\n\nDate="+date1);
System.out.println("Name of the A/C holder="+name);
System.out.println("A/c No.:"+acno);
System.out.println("Balance Rs:"+amount);
System.out.println("*******************\n");
}


public void main()throws IOException

{

char ans='y';

Bank ob=new Bank();

ob.initial();
System.out.println("New Account Opened:");
ob.display();
while(ans!='n')
{
ob.transaction();
ob.display();
System.out.println("Any More(Yes/No:):");

ans=br.readLine().toLowerCase().charAt(0);

}
System.out.println("Opted for Loan (Yes/No):"); 
ans=br.readLine().toLowerCase().charAt(0);
if(ans=='y')
{
ob.loan();
ob.display();
}
}
}

No comments:

Post a Comment

Subscribe via email

Enter your email address:

Delivered by FeedBurner