Shailrshah

A Bank Account Stimulation

Oct 10th, 2013
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.07 KB | None | 0 0
  1. import java.util.Scanner;
  2. class BankAccount{
  3.     static String name;
  4.     static int type;
  5.     static long balance;
  6.     static double ac_no;
  7.     static void assign(){
  8.         name = "XYX ABC";
  9.         type = 1;
  10.         balance = 1000;
  11.         ac_no = 432984123;
  12.     }
  13.     static long deposit(long n){
  14.         return n+balance;
  15.     }
  16.     static long withdraw(long n){
  17.         if(n>balance) System.out.println("The balance is too low.");
  18.         else return balance - n;
  19.         return balance;
  20.     }
  21.     static void display(){
  22.         System.out.println("\tName\tBalance");
  23.         System.out.print("\t"+name+"\t"+balance);
  24.     }
  25.     public static void main(String [] args){
  26.         Scanner sc = new Scanner(System.in);
  27.         assign();
  28.         while(true){
  29.             System.out.print("\n1.Deposit 2. Withdraw 3.View Details 4.Exit: ");
  30.             int n = sc.nextInt();
  31.             switch(n){
  32.                 case 1: System.out.print("Enter the amount to deposit: ");
  33.                         balance = deposit(sc.nextLong());
  34.                         break;
  35.                 case 2: System.out.print("Enter the amount to withdraw: ");
  36.                         balance = withdraw(sc.nextLong());
  37.                         break;
  38.                 case 3: display();
  39.                         break;
  40.                 case 4: return;
  41.             }
  42.         }
  43.     }
  44. }
Add Comment
Please, Sign In to add comment