Bank-Account-Manager

View the Project on GitHub Abdulqadir8604/Bank-Account-Manager

package com.example.bankAccount;


import java.util.Scanner;

public class App {
    public static void main(String[] args) {
        // Scanner input = new Scanner(System.in);

        BankAccount cus1 = new BankAccount("Lamiya", "LM00100111");
        cus1.showMenu();
//        com.example.bankAccount.BankAccount cus2 = new com.example.bankAccount.BankAccount("Abdulqadir", "AQ00080604");
//        cus2.showMenu();

    }
}
class BankAccount
{
    int balance;
    int previousTransaction;
    String customerName;
    String customerId;

    BankAccount(String cname, String cid) {
        customerName = cname;
        customerId = cid;
    }
    void deposit(int amount){
        if(amount != 0){
            balance = balance + amount;
            previousTransaction = amount;
        }
    }
    void withdraw(int amount){
        if(amount != 0 ){
            balance = balance - amount;
            previousTransaction = -amount;
        }
    }
    void getPreviousTransaction(){
        if(previousTransaction > 0){
            System.out.println("Deposited: "+previousTransaction);
        }else if(previousTransaction < 0){
            System.out.println("Withdrawn: "+Math.abs(previousTransaction));
        }else{
            System.out.println("No Transaction occurred");
        }
    }
    void showMenu(){
        char option = '\0';
        Scanner input = new Scanner(System.in);
        System.out.println("Welcome "+customerName);
        System.out.println("Your ID is "+customerId);
        System.out.println("\n");
        System.out.println("A. Check Balance");
        System.out.println("B. Deposit");
        System.out.println("C. Withdraw");
        System.out.println("D. Previous Transactions");
        System.out.println("E. Exit");
        do{
            System.out.println("**************************************************************************************");
            System.out.println("Enter an option");
            System.out.println("**************************************************************************************");
            option = input.next().charAt(0);
            System.out.println("\n");

            switch(option) {
                case 'A':
                    System.out.println("-------------------------------------------------");
                    System.out.println("Balance = " + balance);
                    System.out.println("-------------------------------------------------");
                    System.out.println("\n");
                    break;
                case 'B':
                    System.out.println("-------------------------------------------------");
                    System.out.println("Enter an amount to deposit: ");
                    System.out.println("-------------------------------------------------");
                    int amount = input.nextInt();
                    deposit(amount);
                    System.out.println("\n");
                    break;
                case 'C':
                    System.out.println("-------------------------------------------------");
                    System.out.println("Enter the amount to withdraw: ");
                    System.out.println("-------------------------------------------------");
                    int amount2 = input.nextInt();
                    withdraw(amount2);
                    System.out.println("\n");
                    break;
                case 'D':
                    System.out.println("-------------------------------------------------");
                    getPreviousTransaction();
                    System.out.println("-------------------------------------------------");
                    System.out.println("\n");
                    break;
                case 'E':
                    System.out.println("ThankYou for using our services");
                    break;
                default:
                    System.out.println("Invalid Option!! Please enter again.");
                    break;
            }
        }while(option != 'E');
    }
}