Friday, 16 January 2015

Bank Application in java

import java.util.*;
public class BankAccount 
{
Scanner sc=new Scanner(System.in);
 String name;
 int accno;
 int y;
 float r,i,t,bal,amt;
void getdata(String name,int accno)
   {
  this.name=name;
  this.accno=accno;
   }
 float deposit()
   {
System.out.print("enter amount to deposit");
amt=sc.nextFloat();
if(amt<0)
 {
System.out.print("Please re-enter amount to deposit");
    return 1;
 }
bal=bal+amt;
 return 0;
   }

 void display()
 {
 System.out.println(name);
 System.out.println(accno);
 System.out.println(bal);
 }

 }
class Current extends BankAccount

float withdraw()
   {
 System.out.print("enter amount to withdraw");
 amt=sc.nextFloat();
 if(bal<amt)
 {
 System.out.print("insufficient balance");
 return 1;
 }
 bal=bal-amt;
 return 0;
   }
}

class Saving extends BankAccount{
float interest()
 {
 if(bal!=0)
 {
   System.out.print("enter amount years and rate");
// a=sc.nextFloat();
   y=sc.nextInt();
    r=sc.nextFloat();
    System.out.println("bal is"+bal);
   i=(bal*y*r)/100; 
   System.out.println("interest is"+i);
   t=bal+i;
   System.out.println("t is"+t);
 }
 return 0;  
 }
}
import java.util.Scanner;
public class Test {
private static Scanner sc;

public static void main(String[] args)throws Exception
{
 Saving s=new Saving();
Current c=new Current();
sc = new Scanner(System.in);
int z,y;
int menu,n1;
String st,st1="";
System.out.println("Enter your option \n 1: savings 2: current");
z=sc.nextInt();
switch(z)
{
case 1:
String type="savings";
// System.out.println("enter name");
//  st1=sc.nextLine();
// st=st1;
st="rupa";
System.out.println("enter account number");
 n1=sc.nextInt();
s.getdata(st,n1);
//boolean quit=false;
//while(!quit)
do
{
System.out.print("enter your choice \n 1.deposit amount 2. display 3.interest 4.exit ");
 menu=sc.nextInt();
   switch(menu)
   {
    case 1:
  s.deposit();
  break;
    case 2:
   s.display();
   break;
    case 3:
     s.interest();
     break;
    case 4:
// System.out.print(0);
    break;
     }
}while(menu<=5);//end of while
break;
case 2:type="current";
//System.out.println("enter name");
// st=sc.nextLine();
 st="swarupa";
 System.out.println(st);
System.out.println("enter account number");
 n1=sc.nextInt();
 c.getdata(st,n1);
do
{
System.out.print("enter your choice \n 1.deposit amount 2.withdraw 3. display  4.exit ");
 y=sc.nextInt();
   switch(y)
   {
    case 1:
  c.deposit();
  break;
    case 2:
  c.withdraw();
   break;
    case 3:
   c.display();
   break;
    case 4:
    break;
     }
}while(y<=5);
break;
}
}
}

No comments:

Post a Comment