Answer to Question #231869 in Java | JSP | JSF for jerry

Question #231869

Develop a java application using Inheritance as per the following. Create a super class called

CashTree which demonstrate any ATM Machine. Have attributes like name, codeno, location,

etc. Add functionalities like ViewBalance, WithDraw and Deposit in super class. Derive two

sub classes SBI_Bank, and HDFC_Bank with additional properties such as customer_name,

balance and redefine those super class functionalities according to the nature of specified

bank (differenciate via service_charges, interest rate, and maximum withdraw limit etc).

Complete the above scenario using Inheritance, Run Time Polymorphism with Menu driven

options.


1
Expert's answer
2021-09-01T23:57:29-0400
import java.util.Scanner;


public class Main
{
	public static void main(String[] args) {
		System.out.println("Choose a bank:\n1. SBI Bank\n2. HDFC Bank");
		Scanner in=new Scanner(System.in);
		int c=in.nextInt();
		
		if (c==1){
		    System.out.println("Choose an operation to perform:\n1. View Balance\n2. WithDraw\n3. Deposit");
		    int c2=in.nextInt();
		    SBI_Bank s=new SBI_Bank();
		    s.getdata();
		    if (c2==1)
		        s.ViewBalance();
		    else if (c2==2)
		        s.WithDraw();
		    else if (c2==3)
		        s.Deposit();
		}
	    else if(c==2){
	        System.out.println("Choose an operation to perform:\n1. View Balance\n2. WithDraw\n3. Deposit");
		    int c2=in.nextInt();
		    HDFC_Bank h=new HDFC_Bank();
		    h.getdata();
		    if (c2==1)
		        h.ViewBalance();
		    else if (c2==2)
		        h.WithDraw();
		    else if (c2==3)
		        h.Deposit();
	    }
	}
}
class CashTree{
    private String name;
    private int codeno;
    private String location;
    
    public void ViewBalance(){
        
    }
    public void WithDraw(){
        
    }
    public void Deposit(){
        
    }
}


class SBI_Bank extends CashTree{
    double service_charges=230.50;
    int interest_rate=11;
    double maximum_withdraw_limit=700000;
    String customer_name;
    double balance;
    public void getdata(){
        Scanner in=new Scanner(System.in);
        System.out.println("Enter customer name: ");
        customer_name=in.next();
        System.out.println("Enter current balance of the customer: ");
        balance=in.nextDouble();
    }
    public void ViewBalance(){
        System.out.println("Balance= " + balance);
    }
    public void WithDraw(){
        double amount;
        Scanner in=new Scanner(System.in);
        
        System.out.println("Enter amount to WithDraw: ");
        amount=in.nextDouble();
        if (amount>maximum_withdraw_limit){
            System.out.println("The amount of money cannot be withdrawn. The maximum amount that can be withdrawn is: "+maximum_withdraw_limit);
            
        }
        else if (amount<=0){
            System.out.println("Insufficient amount");
        } 
        else{
            balance=balance-(service_charges+amount);
            System.out.println("You have withdrawn: "+amount+". New Balance is :"+balance);
        }
    }
    public void Deposit(){
        double amount;
        Scanner in=new Scanner(System.in);
        
        System.out.println("Enter amount to deposit: ");
        amount=in.nextDouble();
        balance=balance+amount;
        System.out.println("You have deposited "+amount+"New account balance is: "+balance);
        
    }
    
}


class HDFC_Bank extends CashTree{
    double service_charges=250.50;
    int interest_rate=10;
    double maximum_withdraw_limit=500000;
    String customer_name;
    double balance;
    
    public void getdata(){
        Scanner in=new Scanner(System.in);
        System.out.println("Enter customer name: ");
        customer_name=in.next();
        System.out.println("Enter current balance of the customer: ");
        balance=in.nextDouble();
    }
    public void ViewBalance(){
        System.out.println("Balance= " + balance);
    }
    public void WithDraw(){
        double amount;
        Scanner in=new Scanner(System.in);
        
        System.out.println("Enter amount to WithDraw: ");
        amount=in.nextDouble();
        if (amount>maximum_withdraw_limit){
            System.out.println("The amount of money cannot be withdrawn. The maximum amount that can be withdrawn is: "+maximum_withdraw_limit);
            
        }
        else if (amount<=0){
            System.out.println("Insufficient amount");
        } 
        else{
            balance=balance-(service_charges+amount);
            System.out.println("You have withdrawn: "+amount+". New Balance is :"+balance);
        }
    }
    public void Deposit(){
        double amount;
        Scanner in=new Scanner(System.in);
        
        System.out.println("Enter amount to deposit: ");
        amount=in.nextDouble();
        balance=balance+amount;
        System.out.println("You have deposited "+amount+"New account balance is: "+balance);
        
    }
    
}

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