Sie sind auf Seite 1von 10

Program: import java.io.*; import java.util.

*; class account { String name; String accno; } class current extends account { int bal,dep,wid,a; void dep() { bal=dep+bal; System.out.println("Deposited successfully"); System.out.println("New balance:"+bal); } void wtw() { a=bal-wid; if(a<1000) { System.out.println("Cannot withdraw");

System.out.println("Balance:"+bal); } else { bal=a; System.out.println("Withdrawn successfully"); System.out.println("New balance:"+bal); } } void disp() { System.out.println("Balance in current account:"+bal); } } class savings extends account { int b,d,w,i,j; void depos() { b=d+b; System.out.println("Deposited successfully"); System.out.println("New balance:"+b); }

void withd() { j=b-w; if(j<0) { System.out.println("Cannot withdraw"); System.out.println("Balance:"+b); } else { b=j; System.out.println("Withdrawn successfully"); System.out.println("New balance:"+b); } } void interest() { i=b*8/100; System.out.println("Interset:"+i); } void display() { System.out.println("Balance in savings account:"+b);

} } class hierar { public static void main(String args[])throws Exception { int ch; savings s=new savings(); current c=new current(); System.out.println("Enter the customer name,account no"); DataInputStream his=new DataInputStream(System.in); s.name=his.readLine(); s.accno=his.readLine(); s.b=2000; c.bal=3000; do { System.out.println("1.Deposit in Savings account "); System.out.println("2.Withdraw from Savings account "); System.out.println("3.Deposit in Current account "); System.out.println("4.Withdraw from Current account "); System.out.println("5.Calculate interest in Savings account "); System.out.println("6.Display balance");

System.out.println("7.Exit"); System.out.println("Enter your choice"); Scanner sc=new Scanner(new DataInputStream(System.in)); ch=sc.nextInt(); switch(ch) { case 1: Scanner tc=new Scanner(new DataInputStream(System.in)); System.out.println("Enter the amount to be deposited"); s.d=tc.nextInt(); s.depos(); break; case 2: System.out.println("Enter the amount to be withdrawed"); Scanner uc=new Scanner(new DataInputStream(System.in)); s.w=uc.nextInt(); s.withd(); break; case 3: Scanner vc=new Scanner(new DataInputStream(System.in)); System.out.println("Enter the amount to be deposited"); c.dep=vc.nextInt(); c.dep();

break; case 4: System.out.println("Enter the amount to be withdrawed"); Scanner wc=new Scanner(new DataInputStream(System.in)); c.wid=wc.nextInt(); c.wtw(); break; case 5: s.interest(); break; case 6: s.display(); c.disp(); break; case 7: System.exit(0); } }while(ch<7); } }

Output: Enter the customer name,account no siva 234567 234567 1.Deposit in Savings account 2.Withdraw from Savings account 3.Deposit in Current account 4.Withdraw from Current account 5.Calculate interest in Savings account 6.Display balance 7.Exit Enter your choice 1 Enter the amount to be deposited 2000 Deposited successfully New balance:4000 1.Deposit in Savings account 2.Withdraw from Savings account 3.Deposit in Current account 4.Withdraw from Current account 5.Calculate interest in Savings account 6.Display balance

7.Exit Enter your choice 2 Enter the amount to be withdrawed 200 Withdrawn successfully New balance:3800 1.Deposit in Savings account 2.Withdraw from Savings account 3.Deposit in Current account 4.Withdraw from Current account 5.Calculate interest in Savings account 6.Display balance 7.Exit Enter your choice 3 Enter the amount to be deposited 200 Deposited successfully New balance:3200 1.Deposit in Savings account 2.Withdraw from Savings account 3.Deposit in Current account

4.Withdraw from Current account 5.Calculate interest in Savings account 6.Display balance 7.Exit Enter your choice 4 Enter the amount to be withdrawed 300 Withdrawn successfully New balance:2900 1.Deposit in Savings account 2.Withdraw from Savings account 3.Deposit in Current account 4.Withdraw from Current account 5.Calculate interest in Savings account 6.Display balance 7.Exit Enter your choice 5 Interset:304 1.Deposit in Savings account 2.Withdraw from Savings account 3.Deposit in Current account

4.Withdraw from Current account 5.Calculate interest in Savings account 6.Display balance 7.Exit Enter your choice 6 Balance in savings account:3800 Balance in current account:2900 1.Deposit in Savings account 2.Withdraw from Savings account 3.Deposit in Current account 4.Withdraw from Current account 5.Calculate interest in Savings account 6.Display balance 7.Exit Enter your choice 7

Das könnte Ihnen auch gefallen