Answer to Question #249476 in Java | JSP | JSF for Locos

Question #249476

Develop an application in Java for automating the Banking Operations using interfaces.

Create an interface called “Transaction” which contains the functions such as deposit,

withdraw, and viewBalance. Create another interface called “Displayable” which

contains the Display () function to display the account details.

Create an abstract class called “Account” with bank account details such as acc_name,

acc_no, and balance. Add necessary constructors.

Create a “Bank” class which implements the “Transaction”, “Displayable” interfaces

and inherits “Account” class.

Perform menu driven operations like Deposit, Withdraw and Balance Enquiry, View

Account Details from a Main class. Write logics in the corresponding methods.


1
Expert's answer
2021-10-11T00:05:34-0400
import java.util.Scanner;
interface Transaction{ 
    void deposit();
    void withdraw(); 
    void viewBalance(); 
}  
interface Displayable{  
    void Display(); 
}  








abstract class Account{ 
    public String acc_name;
    public int acc_no; 
    public double balance;
    public Account(double b,String a1, int a2){
        balance=b;
        acc_name=a1;
        acc_no=a2;
    }
}
public class Main{ 
    public static void main(String args[]){  
        Scanner in=new Scanner(System.in);
        Bank b=new Bank(500.00,"abcd",1234);
        int c;
        System.out.println("Choose an operation to perform:\n1. Deposit\n2. Withdraw\n3. Balance Enquiry\n4. View Account Details ");
        c=in.nextInt();
        if (c==1)
            b.Display();
        else if (c==2) 
            b.deposit();
        else if (c==3)
            b.withdraw();
        else if (c==4)
            b.viewBalance();
     }  
} 








class Bank extends Account implements Transaction, Displayable {
    public Bank(double b,String a1, int a2){
        super(b,a1,a2);
    }
    public void deposit(){
        double amount;
        System.out.println("Enter amount to deposit: ");
        Scanner in=new Scanner(System.in);
        amount=in.nextDouble();
        balance=balance+amount;
        System.out.println("You have deposited "+amount+".Your current balance is: "+balance);
    }
    public void withdraw(){
        double amount;
        System.out.println("Enter amount to withdraw: ");
        Scanner in=new Scanner(System.in);
        amount=in.nextDouble();
        balance=balance-amount;
        System.out.println("You have withdrawn "+amount+".Your current balance is: "+balance);
    }
    public void viewBalance(){
        System.out.println("Your account balance is: "+balance);
    }
    public void Display(){
        System.out.println("Account name: "+acc_name);
        System.out.println("Account number: "+acc_no);
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS