Witshaper is the Professional (Computing Skills, English Learning and Soft Skills) Skill Development Training Center. We provide Professional IT Courses and Soft Skill Training in Dehradun to Students, Employees and organization. Who wish to pursue a career in IT Technology. Witshaper is led by a motivated team of IT experts and Soft Skill Professionals. We provide high quality trainings. Our Emphasis is on giving the practical knowledge to the students, so that they will get to know in depth and never forget what they opt, we provide to the students real learning environment. Witshaper prepares students and professionals to be the part of this growing industry. Be a part of Witshaper and get your dreams successful

Tuesday, 12 May 2015

JAVA Program to represent Bank System using inheritance function ,constructor and user input


import java.io.*;
/*Base class Account*/
class Account
{
 double accBal;
 Account()
 {
 }
 Account(double d)
 {
  accBal=d;
  if(accBal<1000)
  {
   System.out.println("Invlaid amount. Amount should be > or = 1000");
   accBal=1000;
  }
 }
 
 void credit(double amt)
 {
  accBal=accBal+amt;
 }
 
 void debit(double amt)
 {
  if(amt>accBal)
   System.out.println("Debit amount exceeded account balance");
  else
   accBal=accBal-amt;
 }
 
 double getBalance()
 {
  return(accBal);
 }
}
//Derived class SavingsAccount
class SavingsAccount extends Account
{
 double rate;
 SavingsAccount(double r,double amt)
 {
  super(amt); 
  rate=r;
 }

 public void calculateInterest()
 {
  accBal=accBal*rate;
 }
}
class CheckingAccount extends Account
{
 double fee;
 CheckingAccount(double f,double amt)
 {
  super(amt);
  fee=f;
 }
 void credit(double amt)
 {
  accBal=accBal+amt-fee;
 }
 void debit(double amt)
 {
  if(amt>accBal)
   System.out.println("Debit amount exceeded account balance");
  else
   accBal=accBal-amt-fee;
 }

 
}
class Bank
{
 public static void main(String args[])
 {
  int a,b;
  DataInputStream d= new DataInputStream(System.in);
  double amount,rate =5,fee=100;
 
  try
  {
  System.out.println("Press 1. SavingAccounts 2. Checking Accounts");
  a=Integer.parseInt(d.readLine());
  switch(a)
  {
  case 1:
  System.out.println("Enter amount to open account");
  amount=Double.valueOf(d.readLine());
  SavingsAccount sa=new SavingsAccount(rate,amount); 
  
  System.out.println("Thank you for opening account your Initial Balanceis :"+sa.getBalance());
  do
  {
  System.out.println("Enter choice:\n1.Withdraw\n2.Deposit\n3.CheckBalance\n 4.Exit");
  a=Integer.parseInt(d.readLine()); 
  switch(a)
  {
   case 1:
      System.out.println("Enter amount to withdraw");
      amount=Double.valueOf(d.readLine());
      sa.debit(amount);
      sa.calculateInterest();
      System.out.println("Balance is :"+sa.getBalance());
      break;
   case 2:
      System.out.println("Enter amount to deposit");
      amount=Double.valueOf(d.readLine());
      sa.credit(amount);
      sa.calculateInterest();
      System.out.println("Balance is :"+sa.getBalance());
      break;
   case 3:
      System.out.println("Your balance is"+sa.getBalance());
      break;
  }
  }
  while(a!=4);
  break;
  case 2:
  System.out.println("Enter amount to open account");
  amount=Double.valueOf(d.readLine());
  CheckingAccount ca=new CheckingAccount(fee,amount); 
  
  System.out.println("Thank you for opening account your Initial Balanceis :"+ca.getBalance());
  do
  {
  System.out.println("Enter choice:\n1.Withdraw\n2.Deposit\n3.CheckBalance\n 4.Exit");
  a=Integer.parseInt(d.readLine()); 
  switch(a)
  {
   case 1:
      System.out.println("Enter amount to withdraw");
      amount=Double.valueOf(d.readLine());
      ca.debit(amount);
      System.out.println("Balance is :"+ca.getBalance());
      break;
   case 2:
      System.out.println("Enter amount to deposit");
      amount=Double.valueOf(d.readLine());
      ca.credit(amount);
      System.out.println("Balance is :"+ca.getBalance());
      break;
   case 3:
      System.out.println("Your balance is"+ca.getBalance());
      break;
  }
  }
  while(a!=4);
  break;
  }
  }
  catch(Exception e)
  {}
 }
}

 

No comments:

Post a Comment