import java.io.*;
import java.lang.*;
class Bank
{
double bal,damt,wamt;
String acct_type, acct_name;
int acctno;
void initial(int no, String type,String name,double balance)
{
acctno=no;
acct_type=type;
acct_name=name;
bal=balance;
}
void deposit(double amt)
{
damt=amt;
bal=bal+damt;
System.out.println("Amount Deposited: "+damt);
}
void withdraw(double at)
{
wamt=at;
if(bal>wamt)
{
bal=bal-wamt;
System.out.println("Amount Withdrawn: "+wamt);
}
else
{
System.out.println("Withdrawn Amount greater than balance \n Balance :"+bal);
}
}
void display()
{
System.out.println("Account Number: "+acctno);
System.out.println("Account Type: "+acct_type);
System.out.println("Account Name: "+acct_name);
System.out.println("Account Balance: "+bal);
}
}
class BankDemo
{
public static void main(String args[])throws IOException
{
DataInputStream in=new DataInputStream(System.in);
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String name,type;
int no,choice,i;
double ba,wa,da;
boolean baless=false;
i=0;
System.out.print("Enter account number: ");
no=Integer.parseInt(in.readLine());
System.out.print("Enter account type: ");
type=br.readLine();
System.out.print("Enter account name: ");
name=br.readLine();
do{
System.out.print("Enter account balance: ");
ba=Double.parseDouble(in.readLine());
if(ba<1000)
{
baless=true;
System.out.println("Minimum balance must be Rs.1000");
}
else
baless=false;
}while(baless==true);
Bank b1=new Bank();
b1.initial(no,type,name,ba);
while(i==0)
{
System.out.print("1.Deposit\n2.Withdraw\n3.Display\n4.Exit\nEnter Choice: ");
choice=Integer.parseInt(in.readLine());
switch(choice)
{
case 1:System.out.print("Enter amount to be deposited: ");
da=Double.parseDouble(in.readLine());
b1.deposit(da);
break;
case 2:System.out.print("Enter amount to be withdrawn: ");
wa=Double.parseDouble(in.readLine());
b1.withdraw(wa);
break;
case 3:b1.display();
break;
case 4:i=1;
break;
default: System.out.println("Not a vaild choice.");
}
}
}
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment