From 13ccb3c94ad0079da314d180129f0eec861b7f95 Mon Sep 17 00:00:00 2001 From: Garvit Khandelwal Date: Sat, 4 Nov 2017 05:42:24 +0530 Subject: [PATCH] Added a new java program on banking management system --- Bank.java | 353 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 353 insertions(+) create mode 100644 Bank.java diff --git a/Bank.java b/Bank.java new file mode 100644 index 0000000..3487b11 --- /dev/null +++ b/Bank.java @@ -0,0 +1,353 @@ +/* + ** -------Problem question-----------** + A banking system provides two types of account services to its customers. +1. Saving Account: Using such service customer can deposit amount and can also withdraw amount but customer has to maintain minimum balance (such as 10000/-) after withdrawal. Customer also gets interest on his balance periodically. +2. Current Account: Such service is for the business purpose customers. Current account holder can withdraw beyond minimum balance (also known as overdraft) but penalty will be levied on overdraft. How much overdraft is allowed depends on the credit limit of a customer (Generally decided by the Bank itself). On such account bank does not give interest. +Write a banking management system. +*/ + + + + +/**** Class Account ***/ +import java.util.Scanner; +class Account +{ + private int accno; + private double balance; + protected double minbalance; + + public Account(int ac, double bal, double minbal) + { + accno= ac; + balance = bal; + minbalance = minbal; + } + protected int getAccno() + { + return accno; + } + protected double getBalance() + { + return balance; + } + protected void setBalance(double bal) + { + balance = bal; + } + protected double getMinBalance() + { + return minbalance; + } + protected void setMinBalance(int bal) + { + minbalance = bal; + } +} + +class SavingAccount extends Account +{ + private double interest; + static private double rate; + static int temp = 100; + public SavingAccount(double bal, double minbal) + { + //int accno; + + super(generateAccountNumber(), bal,minbal); + interest =0; + rate = 4.5; + } + private static int generateAccountNumber() + { + return temp++; + } + static public double getRate() + { + return rate; + } + public void deposit(int amt) + { + setBalance(super.getBalance()+amt); + } + public void withdraw(int amt) + { + if(getBalance()-amt >= minbalance) + setBalance(getBalance()-amt); + else + { + System.out.println("Your Balance is less: "+getBalance()); + } + } + public void showBalance() + { + System.out.println("Your Balance is: " + getBalance()); + } + public int getAccno() + { + return super.getAccno(); + } + public static void modifyRate(double irate) + { + rate = irate; + } + public void calInterest() + { + interest = getBalance()*this.getRate()/100; + setBalance(getBalance()+interest); + } + public void showDetails() + { + + System.out.println("Account Type: Saving Account"); + System.out.println("Account No:"+this.getAccno()); + System.out.println("Balance: "+super.getBalance()); + System.out.println("Min Balance: "+super.getMinBalance()); + } + +} +class CurrentAccount extends Account +{ + + private double overdraft; + private double penaltyrate; + private double creditlimit; + private double penalty; + static int temp = 1100; + public CurrentAccount(double bal, double minbal,double credit) + { + //int accno; + + super(generateAccountNumber(), bal,minbal); + creditlimit = credit; + overdraft =0; + penaltyrate = 3.5; + penalty=0; + } + private static int generateAccountNumber() + { + return temp++; + } + public void deposit(int amt) + { + + setBalance(super.getBalance()+amt); + if(getBalance() >=getMinBalance()) + { + penalty = overdraft*penaltyrate; + setBalance(super.getBalance()-penalty); + overdraft =0; + } + else + overdraft = overdraft-amt+penalty; +} + public void withdraw(int amt) + { + + if(getBalance()-getMinBalance()>=amt) + { + setBalance(getBalance()-amt); + penalty = 0; + } + else + if(amt<=creditlimit) + { + overdraft = getBalance()+getMinBalance()-amt; + setBalance(getBalance()-amt); + } + else + { + System.out.println("Your withdrawl request exceeded credit limit: "+getBalance()); + System.out.println("Your credit limit: "+creditlimit); + } + } + public void showBalance() + { + System.out.println("Your Balance is: " + getBalance()); + } + public int getAccno() + { + return super.getAccno(); + } + public void showDetails() + { + + System.out.println("Account Type: Current Account"); + System.out.println("Account No: "+this.getAccno()); + System.out.println("Balance: "+super.getBalance()); + System.out.println("Min Balance: "+super.getMinBalance()); + System.out.println("Credit Limit: "+this.creditlimit); + System.out.println("Overdraft: "+this.overdraft); + System.out.println("Penaltyrate: "+this.penaltyrate); + System.out.println("penalty : "+this.penalty); + + } + +} +/****** Class Bank ******/ +public class Bank +{ + public static int search(SavingAccount save[], int acno, int size) + { + int i; + for(i=0;i=0) + { + System.out.println("Enter the amount to be deposited"); + amt = scan.nextInt() ; + save[pos].deposit(amt); + + } + else + System.out.println("Account does not exist"); + break; + + + case 4 : + System.out.println("Enter the account no"); + accno = scan.nextInt() ; + pos = search(cur,accno,j); + if(pos<0) + { + System.out.println("Account does not exist"); + break; + } + System.out.println("Enter the amount to be deposited"); + amt = scan.nextInt() ; + cur[pos].deposit(amt); break; + case 5 : + System.out.println("Enter the account no"); + accno = scan.nextInt() ; + pos = search(save,accno,i); + if(pos>=0) + { + + System.out.println("Enter the withdrawl amount "); + amt = scan.nextInt() ; + save[pos].withdraw(amt); + } + else + System.out.println("Account does not exist"); + + break; + + case 6 : + System.out.println("Enter the account no"); + accno = scan.nextInt() ; + pos = search(cur,accno,j); + if(pos<0) + { + System.out.println("Account does not exist"); + break; + } + System.out.println("Enter the withdrawl amount "); + amt = scan.nextInt() ; + cur[pos].withdraw(amt); break; + + case 7: System.out.println("Enter the account no"); + accno = scan.nextInt() ; + pos = search(save,accno,i); + if(pos>=0) + + save[pos].showBalance(); + else + System.out.println("Account does not exist"); + break; + + + + case 8: System.out.println("Enter the account no"); + accno = scan.nextInt() ; + pos = search(cur,accno,j); + if(pos<0) + { + System.out.println("Account does not exist"); + break; + } + cur[pos].showBalance(); break; + + case 9: System.out.println("Enter the account no"); + accno = scan.nextInt() ; + pos = search(save,accno,i); + if(pos>=0) + + save[pos].showDetails(); + else + System.out.println("Account does not exist"); + break; + + case 10: System.out.println("Enter the account no"); + accno = scan.nextInt() ; + pos = search(cur,accno,j); + if(pos>=0) + cur[pos].showDetails(); + else + System.out.println("Account does not exist"); + break; + case 11: System.out.println("Bank Software Closed");System.exit(1); + default : System.out.println("Wrong Entry \n "); + + } + + System.out.println("\nDo you want to continue (Type y or n) \n"); + ch = scan.next().charAt(0); // will give the first character of entered string + } while (ch == 'Y'|| ch == 'y'); + } +}