raian008

bank class

Jul 9th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.89 KB | None | 0 0
  1. import java.util.Date;
  2. import java.util.Scanner;
  3.  
  4.  
  5.  
  6. class bank
  7. {
  8.   protected String name;
  9.   protected String nominee;
  10.   protected String id;
  11.   protected double balance;
  12.   protected String accno;
  13.  
  14.     private account DebitAccount[]=new account[100];
  15.     private int count=0;
  16.     public bank(){
  17.     }
  18.     public void createAccount()//name and other input in this position
  19.     {
  20.         account newAccount= new account();
  21.         this.DebitAccount[count]=newAccount;
  22.         count++;
  23.  
  24.  
  25.     Scanner myObj = new Scanner(System.in);
  26.  
  27.     System.out.print("Enter Account No: ");
  28.     String  accno=myObj.nextLine();
  29. System.out.println("Enter name: " );
  30.    String name = myObj.nextLine();
  31.    //System.out.println("Username is: " + name+"\n");
  32.  
  33. System.out.println("Enter nominee: " );
  34. String nominee = myObj.nextLine();
  35.  //System.out.println("nominee is: " + nominee+"\n");
  36.   // this.id=Idgenerator.getId();
  37.    //System.out.println("your acount no  :"+accno);
  38.    //System.out.println("NAME : "+name+" \n"+"account no : "+accno+"\n"+"nominee :"+nominee);
  39.     }
  40.  
  41.  
  42.   public String getId()
  43.   {
  44.     return this.id;
  45.   }
  46.   public void print()
  47.   {
  48.  
  49.       System.out.println("NAME : "+name+" \n"+"account no : "+accno+"\n"+"nominee :"+nominee);
  50.   }
  51.  
  52.   public double getbalance(){
  53.     return balance;
  54.   }
  55.   boolean search(String acn)
  56.   {
  57.     if(accno.equals(accno))
  58.     {
  59.       print();
  60.       return(true);
  61.     }
  62.     return(false);
  63.   }
  64.  
  65.   public boolean deposit(String accno,double amount)
  66.   {
  67.       if(balance >100000 && amount>0)
  68.       {
  69.           return false;
  70.           // System.out.println("You have exceed your deposit limit");
  71.       }else{
  72.         balance += amount;
  73.           return true;
  74.       }
  75.   }
  76.   public boolean withdraw(String accno,double amount)
  77.   {
  78.  
  79.       if (amount >= 0 && amount <= balance)
  80.       {
  81.  
  82.            balance -= amount;
  83.            return true;
  84.       }
  85.  
  86.       return false;
  87.   }
  88.     public static void main(String args[])
  89.     {
  90.         bank B= new bank();
  91.         //B.createAccount();
  92.     Scanner in = new Scanner(System.in);
  93.     System.out.print("How Many Customer U Want to Input : ");
  94.         int n=in.nextInt();
  95.  
  96.       bank  C[]=new bank[n];
  97.       for(int i=0;i<C.length;i++)
  98.       {
  99.         C[i]=new bank();
  100.         C[i].createAccount();
  101.       }
  102.  
  103.  
  104.     int userChoice ;
  105.     String temp;
  106.   boolean quit = false;
  107.  
  108.  
  109.    do {
  110.       //  System.out.println("1. Create Account");
  111.          System.out.println("2. Deposit money");
  112.          System.out.println("3. Withdraw money");
  113.  
  114.          System.out.println("4. Display Account Details");
  115.          System.out.println("0. to quit: \n");
  116.          System.out.print("Enter Your Choice : ");
  117.          userChoice = in.nextInt();
  118.          switch (userChoice) {
  119.  
  120.         /* case 1:
  121.                System.out.print("Enter your Name : ");
  122.                name=strng.nextLine();
  123.                System.out.print("Enter Accout Type : ");
  124.  
  125.                System.out.println("\n\tYour Account Details");
  126.                System.out.println("**************************");
  127.                B.printAccount();
  128.                break;*/
  129.  
  130.        case 2: //  deposit
  131.        in.nextLine();
  132.     System.out.print("Enter your account Number : ");
  133.     temp=in.nextLine();
  134.  if(temp.equals(B.accno)){
  135.  
  136.  
  137.    System.out.print("Enter Amount Of Money to deposit: ");
  138.    double amount=in.nextDouble();
  139.    if(!B.deposit(B.accno,amount)){
  140.     System.out.println("Please enter positive value or Maybe you have exceeded your deposit Amount .");
  141.    }else{
  142.  
  143.      System.out.println(" deposited : "+amount+ " The current balance is : "+B.getbalance());
  144.    }
  145.  
  146.  
  147. }
  148.      else {
  149.          System.out.println("Wrong Accoount Number.");
  150.      }
  151.  
  152.    break;
  153.  
  154.  
  155.          case 3: // withdraw
  156.  
  157.          System.out.print("Enter your account Number : ");
  158.          temp=in.nextLine();
  159.  
  160.          if(temp.equals(B.accno)){
  161.            System.out.println("Please Enter amount to withdraw");
  162.             double amount = in.nextDouble();
  163.            if(!B.withdraw(B.accno,amount)) {
  164.                System.out.println("not enough balance or negative value");
  165.            }
  166.  
  167.            else{
  168.                System.out.println("Successfully withdrew $"+amount+". The current balance is "+B.getbalance());
  169.              }
  170.         }
  171.              else {
  172.                  System.out.println("Wrong Accoount Number.");
  173.              }
  174.  
  175.                break;
  176.  
  177.  
  178.               case 4: // print all info
  179.  
  180.                   System.out.print("displaying account info :\n");
  181.                   //B.print();
  182.  
  183.                   for(int i=0;i<C.length;i++)
  184.                             {
  185.                                 C[i].print();
  186.                             }
  187.  
  188.                   break;
  189.          case 0:
  190.                quit = true;
  191.                break;
  192.          default:
  193.                System.out.println("Wrong Choice.");
  194.                break;
  195.          }
  196.          System.out.println("\n");
  197.    } while (!quit);
  198.  
  199.  
  200.         //b.printAccountDetails("");
  201.  
  202.   }
  203. }
Add Comment
Please, Sign In to add comment