Bank-Acount

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:
Class name : Bank
Data member/instance variable:
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 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

import java.util.Scanner;
public class Bank
	{
		String  name; 
   		int accno ;
		double  p ;
	Bank(String n, int a, double pp)
	{
			name=n; 
   			accno =a;
			p =pp;
	}
void display( ) 
	{
		System.out.println( "Name = "+name); 
   		System.out.println(	"Accout no = "+accno);
		System.out.println(	"Principal amount = " +p;
	}
}

public class Account extends Bank
	{ 
		static 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.print("\n Enter amount");
		amt=sc.nextDouble();
		p=p-amt;.
	}
	void withdraw()
	{
		System.out.print("\n Enter amount");
		amt=sc.nextDouble();
		if(amt>p)
			System.out.println("INSUFFICIENT BALANCE");
		else
			{ 
				p=p-amt;
				if(p<500)
					p=p-(500-p)/10;
			}
	}
	void display()
	{
		super.display();
		System.out.println("Enter amount = "+amt);
	}
}
This entry was posted in Inheritance. Bookmark the permalink.

Leave a Reply

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