Bank Account Inheritance ISC 2016

A superclass Bank has been defined to store the details of a customer. Define a subclass Account that enables transactions for the customer with the bank. The details of both the classes are given below:

Class name: Bank
Data members/instance variables:
name: stores the name of the customer.
accno: stores the account number.
p: stores the principal amount in decimals.
Member functions/methods:
Bank(…): parameterized constructor to assign values to the instance variables.
void display(): displays the details of the customer.

Class name: Account
Data members/instance variables:
amt: stores the transaction amount in decimals.
Member functions/methods:
Account(…): parameterized constructor to assign values to the instance variables of both the classes.
void deposit(): accepts the amount and updates the principal as p = p + amt.
void withdraw(): accepts the amount and updates the principal as p = p – amt. If the withdrawal amount is more than the principal amount, then display the message “INSUFFICIENT BALANCE”. If the principal amount after withdrawal is less than 500, then a penalty is imposed by using the formula p = p – (500 – p) / 10.
void display(): displays the details of the customer.

Assume that the superclass Bank has been defined. Using the concept of inheritance, specify the class Account giving details of the constructor, void deposit(), void withdraw() and void display().

The superclass and the main function need not be written.

class Account extends Bank{
    double amt;
    public Account(String n, int a, double pr){
        super(n, a, pr);
        amt = 0.0;
    }
    public void deposit()throws IOException{
        InputStreamReader in = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(in);
        System.out.print("Amount: ");
        amt = Double.parseDouble(br.readLine());
        p = p + amt;
    }
    public void withdraw()throws IOException{
        InputStreamReader in = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(in);
        System.out.print("Amount: ");
        amt = Double.parseDouble(br.readLine());
        if(amt > p)
            System.out.println("INSUFFICIENT BALANCE");
        else{
            p = p - amt;
            if(p < 500)
                p = p - (500 - p) / 10;
        }
    }
    public void display(){
        super.display();
    }
}

Leave a Reply