Simple Banking System in java

            A banking system has 4 options. Deposit, withdraw, Balance enquiry and exit. The explanation is given below.

Deposit:

              It asks the user to enter the deposit amount. If the amount is greater than zero, it adds to the balance amount.

Withdraw:

              It asks the withdraw amount from the user. If this amount is less than balance amount and greater than zero, then the withdraw amount is deleted from the balance amount.

Otherwise, it displays there is no sufficient amount.

Balance enquiry:

              It displays the balance amount.

Exit:

      It ends the banking system and displays a thank you message.

Program:

import java.util.Scanner;

public class SimpleBankingEg {

    public static void main(String[] args) {

        Scanner scanner1 = new Scanner(System.in);

        double balance_amt = 0.0;

        while (true) {

            System.out.println("\n--- Simple Banking System ---");

            System.out.println("1. Deposit");

            System.out.println("2. Withdraw");

            System.out.println("3. Balance Enquiry");

            System.out.println("4. Exit");

            System.out.print("Choose an option: ");

            int option = scanner1.nextInt();

            switch (option) {

                case 1:

                    System.out.print("Enter deposit amount :");

                    double deposit_amt = scanner1.nextDouble();

                    if (deposit_amt > 0) {

                        balance_amt += deposit_amt;

                        System.out.println(deposit_amt + " is deposited successfully.");

                    } else {

                        System.out.println("Invalid deposit amount.");

                    }

                    break;                   

                case 2:

                      System.out.print("Enter the amount to withdraw:");

                    double withdrawal_amt = scanner1.nextDouble();

                    if (withdrawal_amt > 0 && withdrawal_amt <= balance_amt) {

                        balance_amt -= withdrawal_amt;

                        System.out.println(withdrawal_amt + "is withdrawn successfully.");

                    } else if (withdrawal_amt > balance_amt) {

                        System.out.println("Insufficient balance.");

                    } else {

                        System.out.println("Invalid withdrawal amount.");

                    }

                    break;

                case 3:

                    System.out.println("Your Current Balance is:" + balance_amt);

                    break;

                case 4:

                    System.out.println("Thank you for using the Banking System. Have a nice day");

                    scanner1.close();

                    System.exit(0);

                default:

                    System.out.println("Invalid option. Please try again.");

            }

        }

    }

}

Output:

C:\raji\blog>javac SimpleBankingEg.java

C:\raji\blog>java SimpleBankingEg

--- Simple Banking System ---

1. Deposit

2. Withdraw

3. Balance Enquiry

4. Exit

Choose an option: 1

Enter deposit amount :12000

12000.0 is deposited successfully.

--- Simple Banking System ---

1. Deposit

2. Withdraw

3. Balance Enquiry

4. Exit

Choose an option: 1

Enter deposit amount :23450

23450.0 is deposited successfully.

--- Simple Banking System ---

1. Deposit

2. Withdraw

3. Balance Enquiry

4. Exit

Choose an option: 3

Your Current Balance is:35450.0

--- Simple Banking System ---

1. Deposit

2. Withdraw

3. Balance Enquiry

4. Exit

Choose an option: 2

Enter the amount to withdraw:10000

10000.0is withdrawn successfully.

--- Simple Banking System ---

1. Deposit

2. Withdraw

3. Balance Enquiry

4. Exit

Choose an option: 3

Your Current Balance is:25450.0

--- Simple Banking System ---

1. Deposit

2. Withdraw

3. Balance Enquiry

4. Exit

Choose an option: 4

Thank you for using the Banking System. Have a nice day

This is the sample Banking system implemented in java. Hope this will be useful to you. Keep coding!!!

No comments:

Post a Comment