icse-promo

Question

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

Classname:Bank
Data member/instance variable:
name:stores the name of the customer
accno:stores the account number
p:stores the principal amount in decimals

Memberfunctions/methods:

Bank(…) :parameterized constructor to assign values to the instance variables
void display():displays the details of the customer

Classname:Account
Data member/instance variable:
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 super class 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 super class and the main function need not be written.

Share code with your friends

Share on whatsapp
Share on facebook
Share on twitter
Share on telegram

Code

				
					import java.util.Scanner;
public class Account extends Bank
{
    Scanner sc=new Scanner(System.in);
    double amt;
    Account(String n,String a,double pp)
    {
        super(n,a,pp);
        amt=0.0;
    }

    void deposit()
    {
        System.out.println("Enter amount to deposit");
        amt=sc.nextDouble();
        p=p+amt;
    }

    void withdraw()
    { 
        System.out.println("Enter amount to withdrawal");
        amt=sc.nextDouble();
        if(amt>p)
        {
            System.out.println("INSUFFICIENT  BALANCE");
        }
        else
        {
            p=p-amt;
            if(p< 500)
            {
                p=p-(500-p)/1O;
            }
        }
    }

    void display()
    {
        super.display();
        
    }

}

				
			

Coding Store

Leave a Reply

Your email address will not be published. Required fields are marked *