Bank Account

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

Session – 24

Abstract classes should not be final, since, they are always reusable. Child class of abstract class must
write the body of all the abstract methods present in abstract parent class. if the child class is not
writing body to any one of the abstract methods then the child class becomes abstract and we cannot
create objects of child class.

Write a JAVA program for computing sum of two integers and floats using abstract classes?
Answer:

abstract class Op
{
abstract void sum ();
};

class isum extends Op


{
void sum ()
{
int a,b,c;
a=10;
b=20;
c=a+b;
System.out.println ("INT VALUE = "+c);
}
};

class fsum extends Op


{
void sum ()
{
float f1,f2,f3;
f1=10.26f;
f2=20.32f;
f3=f1+f2;
System.out.println ("FLOAT VALUE = "+f3);
}
};

class AbDemo
{
public static void main (String k [])
{
// Op o1=new Op (); invalid Op o2;
o2=new isum ();
o2.sum ();
o2=new fsum ();
o2.sum ();
}
};
Assume that bank maintains two kind of accounts for customers, one called as
saving account and other as customer account.
The saving account provides compound interest and withdrawl facilities but no
cheque book facility. The current account provides cheqe book facility but no
interest.current account holders should also maintain a minimum balance and if
the balance falls below tyis level,a service charge is imposed.

create a class account that stress customer name, account nos and type of
account.from this device the classes current account and saving account to make
them more specific to their requirements include necessary members functions
in order to achieve the following tasks:-

a ACCEPT DEPOSITS FROM A CUSTOMER AND UPDATE THE


BALANCE.
b. DISPLAY THE BALANCE.
c. COMPUTE AND DEPOSIT INTEREST.
d. PERMIT WITHDRAWL AND UPDATE THE BALANCE.
e. CHECK FOR THE MINIMUM BALANCE, IMPOSE PENALTY AND
UPDATE THE BALANCE.

import java.util.Scanner;
class account
{
private int ac_no;
private String ac_name;
Scanner sc = new Scanner(System.in);
protected int balance;
public void getinfo()
{
System.out.println ("enter the name");
ac_name=sc.next();
System.out.println ("enter the account number:");
ac_no=sc.nextInt();
}

public void display()


{
System.out.println("Account number = "+ac_no +"Name = "+ac_name+
"Balance = "+balance);
}

}
class savings extends account
{
public savings()
{
balance=0;
}
public void withdrawl()
{
System.out.println(" ENTER THE AMOUNT U WANT TO WITHDRAWL");
int amount ;
amount=sc.nextInt();
if(amount>balance)
{
System.out.println(" DONT HAVE ENOUGH BALANCE TO WITHDRAWL");
}
else
{
if(amount >5000)
{
System.out.println("CANT WITHDRAWL THE AMOUNMT >5000/- IN
SAVINGs");
}
else
{
System.out.println("withdrawled amount is : "+amount);
System.out.println("BALANCE IN UR ACCOUNT IS : ");
balance=balance-amount;
System.out.println(balance);
}
}
}
public void deposit()
{

System.out.println ("enter the amount u want to deposit");


int amount;
amount=sc.nextInt();
balance=balance+amount;
System.out.println ("UR BALANCE IS : "+balance);
int r;
r=(int)(amount*(.01));
balance=balance +r;
System.out.println ("BALANCE AFTER ADDING INTEREST IS:"+balance);

}
class current extends account
{
public current()
{
balance=2000;
}
public void withdrawl()
{
System.out.println (" ENTER THE AMOUNT U WANT TO WITHDRAWL");
int amount ;
amount=sc.nextInt();
if(amount>balance)
{
System.out.println (" DONT HAVE ENOUGH BALANCE TO WITHDRAWL");
}
else
{
System.out.println ("withdrawled amount is : "+amount);
System.out.println("BALANCE IN UR ACCOUNT IS : ");
balance=balance-amount;
if (balance<1000)
{
balance=balance-(int)(.01*(1000-balance));
}
System.out.println ( "BALANCE AFTER IMPOSING CHARGE:"+balance);
}
}

public void deposit()


{
System.out.println ("enter the amount u want to deposit");
int amount;
amount=sc.nextInt();
balance=balance+amount;
System.out.println ("UR BALANCE IS : "+balance);

}
public class Demo
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
savings s = new savings();
current c = new current();
int ch;
System.out.println ("Enter account type");
System.out.println ("Press 1 for Saving");
System.out.println ("Press 2 for Current");
ch=sc.nextInt();
if(ch==1)
s.getinfo();
else
c.getinfo();
while(true)
{
System.out.println (" 1. Withdraw 2. deposit 3. display 4. exit");
int c1=sc.nextInt();
switch(c1)
{
case 1:
if(ch==1)
s.withdrawl();
else
c.withdrawl();
break;
case 2:
if(ch==1)
s.deposit();
else
c.deposit();
break;
case 3:
if(ch==1)
s.display();
else
c.display();
break;

case 4:
System.exit(0);
}
}

}
}

output

Enter account type


Press 1 for Saving
Press 2 for Current
1
enter the name: PURVA
enter the account number: 9000

1. TO WITHDRAWL
2. TO DEPOSIT
3. TO DISPLAY
4. TO EXIT

enter the amount u want to deposit 700


UR BALANCE IS : 700
UR BALANCE AFTER ADDING INTEREST IS : 707
1. TO WITHDRAWL
2. TO DEPOSIT
3. TO DISPLAY
4. TO EXIT
4

You might also like