4)In a bank, different customers having saving account. Some customers may have taken a loan from the bank. So bank always maintains information about bank depositors and borrowers. Design a Base class Customer (name, phone-number).Derive a class Depositor (accno , balance) from Customer. Again derive a class Borrower (loan-no, loan-amt) from Depositor. Write necessary member functions to read and display the details of ‘n’ customers.


import java.io.*;
class Customer
{
String cname ;
long phone;
final public void getInfo()throws IOException
{
BufferedReader br= new BufferedReader (new InputStreamReader(System.in));
System.out.println(“Enter Customer Name :=> “);
cname=br.readLine();
System.out.println(“Enter Customer Phone Number :=> “);
phone=Long.parseLong(br.readLine());
}
public void displayInfo()
{
System.out.println(“Customer Name is :=> ” +cname);
System.out.println(“Customer Phone Number is :=> ” +phone);
}

}
class Depositor extends Customer
{
int accno;
double balance;
public void getDepoInfo()throws IOException
{
BufferedReader br= new BufferedReader (new InputStreamReader(System.in));
System.out.println(“Enter Account Number :=> “);
accno=Integer.parseInt(br.readLine());
System.out.println(“Enter balance :=> “);
balance=Double.parseDouble(br.readLine());
}
public void displayDepoInfo()
{
System.out.println(“Account Number is :=> ” +accno);
System.out.println(“Balance is :=> ” +balance);
}
}

class Borrower extends Depositor
{
int loanno;
double loanamt;
public void getBorrowerInfo()throws IOException
{
BufferedReader br= new BufferedReader (new InputStreamReader(System.in));
System.out.println(“Enter Loan Number :=> “);
loanno=Integer.parseInt(br.readLine());
System.out.println(“Enter Loan Amount :=> “);
loanamt=Integer.parseInt(br.readLine());
}
public void displayBorrowerInfo()
{ System.out.println(“Loan Number is :=> ” +loanno);
System.out.println(“Loan Amount is :=> ” +loanamt);
}
}
class BankDemo
{
public static void main (String args[])
{ try
{
BufferedReader br= new BufferedReader (new InputStreamReader(System.in));
System.out.println(“Enter How Many customer :=> “);
int no=Integer.parseInt(br.readLine());
Borrower b[]=new Borrower[no];
for(int i=0;i<no;i++)
{
b[i]=new Borrower();
b[i].getInfo();
b[i].getDepoInfo();
b[i].getBorrowerInfo();
}
for(int i=0;i<no;i++)
{
b[i].displayInfo();
b[i].displayDepoInfo();
b[i].displayBorrowerInfo();
}
}
catch(Exception e)
{
System.out.println(“Error……. “);
}
}
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s