Sunteți pe pagina 1din 6

J.

Nithyanand Kumar JAVA Assignement-2

Create a java application to display menu as follows


i)create account
ii)statement
iii)deposit
iv)withdraw
Use two classes bank and customer. For savings minimum balance is 1000 and for current
minimum balance is 5000. To access the 2,3,4 menus user need to create account first.

import java.io.*;
class bank
{
int acno,bal,damt,wamt;
String name,type,c="savings";
public bank(int a,int b,String n,String t)
{
acno=a;
name=n;
bal=b;
type=t;
}
public void statement()
{
System.out.println("account No \n"+acno+ " \n customer Name "+name+ " \n balance is
"+bal);
}

public void deposit()


{
try
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("enter the amount to be deposited");
damt=Integer.parseInt(br.readLine());
bal=bal+damt;
System.out.println("the balance is "+bal);
}
catch(Exception e)
{
System.out.println(e);
}

}
public void withdraw()

1
J.Nithyanand Kumar JAVA Assignement-2

{
try
{
int i=0;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("enter the amount to be withdrawn");
wamt=Integer.parseInt(br.readLine());
if(type.equals(c))
{
if((bal-wamt)<1000){
System.out.println("amount can't be withdrawn"+c);
i=1;
}
}
else
{
if((bal-wamt)<5000){
System.out.println("amount can't be withdrawn");
i=1;
}
}
if(i==0){
bal=bal-wamt;
System.out.println("balance is"+bal);
}
}
catch(Exception e)
{
System.out.println(e);
}

}
}
class main1
{
public static void main(String s[])
{
int ch=0,a=0,b=0,i=0,tp=0;
String n=null,t=null,sa="savings",c="current";
bank b1=new bank(a,b,n,t);
do{
try
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

2
J.Nithyanand Kumar JAVA Assignement-2

System.out.println("------MENU-------");
System.out.println("1.Create account");
System.out.println("2.Statement");
System.out.println("3.Deposit");
System.out.println("4.Withdraw");
System.out.println("5:Exit");
System.out.println("ENTER UR CHOICE");
ch=Integer.parseInt(br.readLine());
if(ch==1){
System.out.println("Enter Account Number");
a=Integer.parseInt(br.readLine());
System.out.println("Enter customer Name");
n=br.readLine();
System.out.println("Enter type");
t=br.readLine();
if(t.equals(sa))
tp=1000;
else if(t.equals(c))
tp=5000;
else{
System.out.println("\nenter correct type\n"+t+tp);
ch=0;continue;
}
System.out.println("Enter balance as type is:"+t+"balance should be greater than "+tp);
b=Integer.parseInt(br.readLine());
if(b<tp){
System.out.println("entered balance is less than minimum balance,enter balance
above "+tp);
ch=0;continue;
}
}
switch(ch)
{
case 1:b1=new bank(a,b,n,t);
i=1;
break;
case 2:if(i==1)
b1.statement();
else
System.out.println("first create an account\n");
break;
case 3:if(i==1)
b1.deposit();
else

3
J.Nithyanand Kumar JAVA Assignement-2

System.out.println("first create an account\n");


break;
case 4:if(i==1)
b1.withdraw();
else
System.out.println("first create an account\n");
break;
}
}
catch(Exception e)
{
System.out.println(e);
}
}while(ch<5);
}
}

Output:-

4
J.Nithyanand Kumar JAVA Assignement-2

5
J.Nithyanand Kumar JAVA Assignement-2

S-ar putea să vă placă și