Simple Bank Account Process

Submitted by Karthik on

import java.io.*;
class account
{
        int no, type;
        String name;
        double bal;
        account(int x, String y, int z)
        {
                no = x;
                name = y;
                type = z;
                bal = 500;
        }
}
class sav_acc extends account
        {
                DataInputStream ds=new DataInputStream(System.in);
                sav_acc(int x, String y, int z)
                {
                        super(x,y,z);
                }
                void deposit1() throws IOException
                {
                        System.out.println("Enter deposit amount");
                        int dep = Integer.parseInt(ds.readLine());
                        double ci =  dep*(2.5/100);
                        bal = bal + ci + dep;
                        System.out.println("your balance is:" +bal);
                }
                void withdraw1() throws IOException
                {
                        System.out.println("Enter withdraw amount");
                        int wth = Integer.parseInt(ds.readLine());
                        bal = bal - wth;
                        if(bal<500)
                        {
                        System.out.println("Your balance is less than minimum amount");
                        bal = bal + wth;
			}
			else
			System.out.println("withdraw successfully");
                        System.out.println("Your balance is :"+bal);
                        }
                 }
class cur_acc extends sav_acc
 {
 DataInputStream ds = new DataInputStream(System.in);
 cur_acc(int x, String y, int z)
 {
        super(x,y,z);
 }
 void deposit2() throws IOException
 {
 if(type==1)
        deposit1();
 else
 {
 System.out.println("enter deposit amount");
 int dep = Integer.parseInt(ds.readLine());
 bal = bal+dep;
 System.out.println("Your balance is:"+bal);
 }
 }
 void withdraw2() throws IOException
    {
        if(type==1)
                withdraw1();
                else
                {
                System.out.println("Enter the check no:");
                int ch = Integer.parseInt(ds.readLine());
                System.out.println("Enter withdraw amount");
                int wth = Integer.parseInt(ds.readLine());
                bal = bal - wth;
                if (bal <500)
                {
                    System.out.println("Ur balance less than minimum");
                    bal = bal + wth;
                }
                else
                {
                System.out.println("Withdraw successfully");
                System.out.println("Ur balance is:" +bal + "and your withdraw c");
                }
                }
          }
          void display2() throws IOException
          {
                String fac;
                String t;
                if(type==1)
                {
                        fac = "False";
                        t = "Saving";
                }
                else
                {
                        fac="True";
                        t="current";
                }
         System.out.println("=========================================");
         System.out.println("Bank Account ");
         System.out.println("=========================================");
         System.out.println("Account Number    :" +no);
         System.out.println("Customer name    :" +name);
         System.out.println("Account Type    :" +t);
         System.out.println("Checque book    :" +fac);
         System.out.println("Account Number    :" +no);
         System.out.println("Current balance    :" +bal);
         System.out.println("=========================================");
         System.out.println("=========================================");
     }
 }
class BANK
 {
        public static void main(String ar[]) throws IOException
	{
        DataInputStream ds = new DataInputStream(System.in);
        System.out.println("    Bank Account");
        System.out.println("------------------------");
	System.out.println("Enter Account No. :");
        int n = Integer.parseInt(ds.readLine());
        System.out.println("Enter Customer Name :");
        String name = ds.readLine();
        System.out.println("1-> Saving Account");
        System.out.println("2-> Current Account");
        System.out.println("Select Account type");
        int t = Integer.parseInt(ds.readLine());
        cur_acc ob = new cur_acc(n, name, t);
	while(true)
        {
                System.out.println("1. Deposit");
                System.out.println("2. Withdarw");
                System.out.println("3. Balance");
                System.out.println("4. Exit");
                System.out.println("Enter ur choice");
                int ch = Integer.parseInt(ds.readLine());
                switch(ch)
                {
                        case 1: ob.deposit2();
                                break;
                        case 2: ob.withdraw2();
                                break;
                        case 3: ob.display2();
                                break;
                        case 4: System.exit(0);
                                break;
                        default : System.out.println("Enter correct choice");
                        break;
                }
           }
       }
 }