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

/*

Program : To implement a banking system.


Name : Shivam Gupta
Roll No : 424
M.Sc OR Sem 2

*/

import java.util.*;
class bank4
{
String name;
String atype;
int accno;
double bal;
bank4(String n, String at, int ac, double b)
{
name=n;
atype=at;
accno=ac;
bal=b;
}
public void withdraw(double w)
{
try
{
if(w>bal)
throw new Exception();
bal=bal-w;
display();
System.out.println("The Transaction has occured successfully");
}
catch(Exception e)
{
System.out.println("You don't have enough balance!");
}}
public void deposit(double d)
{
bal=bal+d;
display();
System.out.println("Amount successfully deposited");
}
public void display()
{
System.out.println("Name = "+name+"\nAccount Type = "+atype+"\nAccountNumber =
"+accno+"\nBalace = "+bal);
}
public static void main(String arg[])
{
Scanner sc = new Scanner(System.in);
int n=0;
bank4 a=new bank4("Raj","Saving",13454,90000.50);
a.display();
while(n==0)
{
System.out.println("*****Menu*****\n1.Withdraw\n2.Deposit\n3.Account
Information\n4.Exit\nEnter choice = ");
int ch=sc.nextInt();
switch(ch)
{
case 1:
{
System.out.print("Enter the amount to be withdrawn = ");
double w=sc.nextDouble();
a.withdraw(w);
break;
}
case 2:
{
System.out.print("Enter the amount to deposit = ");
double d=sc.nextDouble();
a.deposit(d);
break;
}
case 3:
{ a.display();
break;
}
case 4:
{
System.out.println("Thank you. Visit again.");
n++;
break;
}}
}}
}

/* OUTPUT

C:\PROGRA~1\Java\jdk\bin>java bank4
Name = Raj
Account Type = Saving
AccountNumber = 13454
Balace = 90000.5
*****Menu*****
1.Withdraw
2.Deposit
3.Account Information
4.Exit
Enter choice =
1
Enter the amount to be withdrawn = 300
Name = Raj
Account Type = Saving
AccountNumber = 13454
Balace = 89700.5
The Transaction has occured successfully
*****Menu*****
1.Withdraw
2.Deposit
3.Account Information
4.Exit
Enter choice =
2
Enter the amount to deposit = 300
Name = Raj
Account Type = Saving
AccountNumber = 13454
Balace = 90000.5
Amount successfully deposited
*****Menu*****
1.Withdraw
2.Deposit
3.Account Information
4.Exit
Enter choice =
3
Name = Raj
Account Type = Saving
AccountNumber = 13454
Balace = 90000.5
*****Menu*****
1.Withdraw
2.Deposit
3.Account Information
4.Exit
Enter choice =

*/

You might also like