Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class bankAcc
- {
- int bankAcc1(int balance2)
- {
- System.out.println("Enter which operation you want to do: ");
- System.out.println("1. Add Balance.");
- System.out.println("2. Deduct Balance.");
- int choice =obj1.nextInt();
- switch(choice)
- {
- case 1:
- System.out.println("Enter the amount to be added: ");
- int newBal = obj1.nextInt();
- balance2 = balance2 + newBal;
- break;
- case 2:
- System.out.println("Enter the amount to be deducted: ");
- int newBal1 = obj1.nextInt();
- if (newBal1 > balance2)
- {
- System.out.println("Sorry Balance is not sufficient to deduct!");
- }
- balance2 = balance2 - newBal;
- break;
- }
- System.out.println("Your New Balance is: " + balance2);
- }
- }
- public class Main
- {
- public static void main (String []args)
- {
- Scanner obj1 = new Scanner(System.in); // for taking input from Scanner class
- bankAcc obj = new bankAcc(); //for the class
- System.out.println("Enter your details: ");
- System.out.println("Enter your Name: ");
- String cus1Name = obj1.nextLine();
- System.out.println("Enter your Accounnt Number");
- String acc1Num= obj1.nextLine();
- System.out.println("Enter your Email Id: ");
- String email1 = obj1.nextLine();
- System.out.println("Enter your Phone Number: ");
- int phNum1= obj1.nextInt();
- System.out.println("Enter your Balance: ");
- int balance1= obj1.nextInt();
- obj.bankAcc1(balance1); //passed the values to the method
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement