import java.io.*;
/*Base class Account*/
class Account
{
double accBal;
Account()
{
}
Account(double d)
{
accBal=d;
if(accBal<1000)
{
System.out.println("Invlaid amount. Amount should be > or = 1000");
accBal=1000;
}
}
void credit(double amt)
{
accBal=accBal+amt;
}
void debit(double amt)
{
if(amt>accBal)
System.out.println("Debit amount exceeded account balance");
else
accBal=accBal-amt;
}
double getBalance()
{
return(accBal);
}
}
//Derived class SavingsAccount
class SavingsAccount extends Account
{
double rate;
SavingsAccount(double r,double amt)
{
super(amt);
rate=r;
}
public void calculateInterest()
{
accBal=accBal*rate;
}
}
class CheckingAccount extends Account
{
double fee;
CheckingAccount(double f,double amt)
{
super(amt);
fee=f;
}
void credit(double amt)
{
accBal=accBal+amt-fee;
}
void debit(double amt)
{
if(amt>accBal)
System.out.println("Debit amount exceeded account balance");
else
accBal=accBal-amt-fee;
}
}
class Bank
{
public static void main(String args[])
{
int a,b;
DataInputStream d= new DataInputStream(System.in);
double amount,rate =5,fee=100;
try
{
System.out.println("Press 1. SavingAccounts 2. Checking Accounts");
a=Integer.parseInt(d.readLine());
switch(a)
{
case 1:
System.out.println("Enter amount to open account");
amount=Double.valueOf(d.readLine());
SavingsAccount sa=new SavingsAccount(rate,amount);
System.out.println("Thank you for opening account your Initial Balanceis :"+sa.getBalance());
do
{
System.out.println("Enter choice:\n1.Withdraw\n2.Deposit\n3.CheckBalance\n 4.Exit");
a=Integer.parseInt(d.readLine());
switch(a)
{
case 1:
System.out.println("Enter amount to withdraw");
amount=Double.valueOf(d.readLine());
sa.debit(amount);
sa.calculateInterest();
System.out.println("Balance is :"+sa.getBalance());
break;
case 2:
System.out.println("Enter amount to deposit");
amount=Double.valueOf(d.readLine());
sa.credit(amount);
sa.calculateInterest();
System.out.println("Balance is :"+sa.getBalance());
break;
case 3:
System.out.println("Your balance is"+sa.getBalance());
break;
}
}
while(a!=4);
break;
case 2:
System.out.println("Enter amount to open account");
amount=Double.valueOf(d.readLine());
CheckingAccount ca=new CheckingAccount(fee,amount);
System.out.println("Thank you for opening account your Initial Balanceis :"+ca.getBalance());
do
{
System.out.println("Enter choice:\n1.Withdraw\n2.Deposit\n3.CheckBalance\n 4.Exit");
a=Integer.parseInt(d.readLine());
switch(a)
{
case 1:
System.out.println("Enter amount to withdraw");
amount=Double.valueOf(d.readLine());
ca.debit(amount);
System.out.println("Balance is :"+ca.getBalance());
break;
case 2:
System.out.println("Enter amount to deposit");
amount=Double.valueOf(d.readLine());
ca.credit(amount);
System.out.println("Balance is :"+ca.getBalance());
break;
case 3:
System.out.println("Your balance is"+ca.getBalance());
break;
}
}
while(a!=4);
break;
}
}
catch(Exception e)
{}
}
}
No comments:
Post a Comment