Bank Example

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

Explaining Inheritance in java using Bank Accounts Example

class account
{
int ac;
String nm,ad,ph;
double bl;
account(int i, String n, String a, String p, double d)
{
ac=i;
nm=n;
ad=a;
ph=p;
bl=d;
}

public void accountholder()


{
System.out.println(“Account Number :”ac);
System.out.println(“Account Holder Name :”+nm);
System.out.println(“Account Holder Address :”ad);
System.out.println(“Account Holder Phone :”+ph);
System.out.println(“Account Holder Balance :”+bl);
}

class savingac extends account


{
double intr;
savingac(int i, String n, String a, String p, double d, double in){
super(i,n,a,p,d);
intr=in;
}

public void diplaybalance(double wamt)


{
double bal=bl-wamt;
System.out.println(“Intrest :”+intr);
System.out.println(“Account Holder Balance :”+bal);
}
public void calculateintrest()
{
double it=(bl*intr)/100;
System.out.println(“Intrest for Year :”+it);
}

public class Main{

public static void main(String[] args)throws IOException {

BufferedReader br= BufferedReader(new InputStreamReader(system.in));

System.out.println(“Enter Account Number :”);


int acno=Integer.parseInt(br.readLine());
System.out.println(“Enter Account Holder Name :”);
String acnm=br.readLine();

System.out.println(“Enter Account Holder Address :”);


String acad=br.readLine();

System.out.println(“Enter Account Holder Phone :”);


String acph=br.readLine();

System.out.println(“Enter Account Holder Balance :”);


double acbl=Double.parsedouble(br.readLine());

System.out.println(“Enter Account Intrest :”);


double acin=Double.parseDouble(br.readLine());

System.out.println(“Enter Withdrawal amount :”);


double acw=Double.parseDouble(br.readLine());

savingac sac=new savingac(acno,acnm, acad,acph,acbl,acin);


sac.accountholder();
sac.diplaybalance();
sac.calculateintrest();
}
}

You might also like