SHARE
TWEET

Untitled

a guest Dec 6th, 2019 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2. public class bankAcc
  3. {
  4. int bankAcc1(int balance2)
  5. {
  6.   System.out.println("Enter which operation you want to do: ");
  7.   System.out.println("1. Add Balance.");
  8.   System.out.println("2. Deduct Balance.");
  9.  
  10.   int choice =obj1.nextInt();
  11.  
  12.   switch(choice)
  13.   {
  14.     case 1:
  15.     System.out.println("Enter the amount to be added: ");
  16.     int newBal = obj1.nextInt();
  17.     balance2 = balance2 + newBal;
  18.     break;
  19.    
  20.     case 2:
  21.     System.out.println("Enter the amount to be deducted: ");
  22.     int newBal1 = obj1.nextInt();
  23.     if (newBal1 > balance2)
  24.    {
  25.      System.out.println("Sorry Balance is not sufficient to deduct!");  
  26.     }
  27.      balance2 = balance2 - newBal;
  28.      break;
  29.   }
  30.  
  31.    System.out.println("Your New Balance is: " + balance2);
  32. }
  33. }
  34.  
  35. public class Main
  36. {
  37. public static void main (String []args)
  38. {
  39.    Scanner obj1 = new Scanner(System.in); // for taking input from Scanner class
  40.    bankAcc obj = new bankAcc(); //for the class
  41.  
  42.   System.out.println("Enter your details: ");
  43.  
  44.   System.out.println("Enter your Name: ");
  45.   String cus1Name = obj1.nextLine();
  46.  
  47.   System.out.println("Enter your Accounnt Number");
  48.   String acc1Num= obj1.nextLine();
  49.  
  50.   System.out.println("Enter your Email Id: ");
  51.   String email1 = obj1.nextLine();
  52.  
  53.   System.out.println("Enter your Phone Number: ");
  54.   int phNum1= obj1.nextInt();
  55.  
  56.   System.out.println("Enter your Balance: ");
  57.   int balance1= obj1.nextInt();
  58.  
  59.   obj.bankAcc1(balance1); //passed the values to the method
  60. }
  61. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top