saic

an anonymous user · August 06, 2022
import java.util.*;
class Bank {
    public static void main(String[] args) {
        Account obj = new Account("sai","AC2237713");
        obj.showMenu();
    }
}
class Account{
    double balance;
    double previousTransaction;
    String customerName;
    String customerId;
    public Account(String customerName,String customerId)
    {
       this.customerName = customerName ;
       this.customerId = customerId;
    }

    void deposit(int amount){
        if(amount!=0)
        {
        balance = this.balance + amount;
        previousTransaction = amount;
        }
     }
     void withdrawl(int amount){
         if(amount!=0)
         {
             balance = balance - amount;
             previousTransaction = -amount;
         }
     }
     void getPreviuosTransaction(){
         if(previousTransaction>0)
             System.out.println("Deposited : "+previousTransaction);
        else if(previousTransaction<0)
             System.out.println("Withdrawl : " + Math.abs(previousTransaction));
         else
              System.out.println("No transaction occured");
     }
     void showMenu(){
         char option = '\0';
         Scanner sc = new Scanner(System.in);
         System.out.println("welcome : "+ customerName);
         System.out.println(" Your id : "+ customerId);
         //System.out.println("\n");
         
          System.out.println("A : Check your balance");
           System.out.println("B : Deposite");
            System.out.println("C : Withdrawl");
             System.out.println("D : Previous Transaction");
              System.out.println("E : Exit the screen");
              
              do {
                   System.out.println("*+*+*+*+*+*+*+*+*+*+*");
                   System.out.println("\n");
                    System.out.println("Enter your option");
                     option = sc.next().charAt(0);
                     
                      System.out.println("\n");
                
                switch(option){
                    case 'A' :
                         System.out.println("Balance = "+ this.balance);
                         System.out.println("\n");
                         break;
                         
                    case 'B' :
                         System.out.println("enter an amount to deposit");
                         int amount = sc.nextInt();sc.nextLine();
                         deposit(amount);
                         System.out.println("\n");
                         break;
                         
                    case 'C' :
                          System.out.println("enter an amount to withdraw");
                         int amount2 = sc.nextInt();
                         withdrawl(amount2);
                         System.out.println("\n");
                         break;
                         
                    case 'D' :
                        getPreviuosTransaction();
                        System.out.println("\n");
                        break;
                    
                    case 'E' :
                        System.out.println("Exit");
                        
                        break;
                        
                }
              }
                while(option != 'E');{
                System.out.println("Thank you for using our service");
                }
              
     }
}
Output
(Run the program to view its output)

Comments

Please sign up or log in to contribute to the discussion.