Posted by: bange May 3, 2011
IT -- Solutions Center[Forum]
Login in to Rate this Post:     0       ?        
Baaki afai garnu kere,

/**
 *
 * @author bange
 *
 */
abstract class Account
{
    private int id;
    private String name;
    private double balance;
    
    public int getId()
    {
        return id;
    }
    public void setId(int id)
    {
        this.id = id;
    }
    public String getName()
    {
        return name;
    }
    public void setName(String name)
    {
        this.name = name;
    }
    public double getBalance()
    {
        return balance;
    }
    
    public void setBalance(double balance)
    {
        this.balance = balance;
    }
    abstract void displayInfo();
    
    void depositCash(double cash)
    {
        balance += cash;
    }
    void transferTo(Account account, double amount)
    {
        account.setBalance(account.getBalance() + amount);
        balance = balance - amount;
    }

}
 class Saving extends Account
{
    private float interestRate;
    private double minimumReq;

    public float getInterestRate()
    {
        return interestRate;
    }

    public void setInterestRate(float interestRate)
    {
        this.interestRate = interestRate;
    }

    public double getMinimumReq()
    {
        return minimumReq;
    }

    public void setMinimumReq(double minimumReq)
    {
        this.minimumReq = minimumReq;
    }
    void calcuateInterest()
    {
        System.out.println(getBalance()*interestRate/1200); // PTR/100 ho? :D
    }
    
    void displayInfo()
    {
        // Enter desired info
        System.out.println("Account type=Saving Id= " + getId() + " Name"  + getName() + "Balance " + getBalance());
    }
}

 class Checking extends Account
{
    private float monthlyFee;
   
    public float getMonthlyFee()
    {
        return monthlyFee;
    }

    public void setMonthlyFee(float monthlyFee)
    {
        this.monthlyFee = monthlyFee;
    }
    
    void displayInfo()
    {
        // Enter desired info
        System.out.println("Account type=Checking Id= " + getId() + " Name "  + getName() + "Balance " + getBalance());
    }
}

public class test
{
  public static void main(String args[])
  {
    Saving savAcc = new Saving();
    savAcc.setId(1);
    savAcc.setName("ram");
    savAcc.setBalance(20000.12);
    Checking checkAcc = new Checking();
    checkAcc.setId(1);
    checkAcc.setName("ram");
    checkAcc.setBalance(3000);
    checkAcc.transferTo(savAcc, 200);
    savAcc.displayInfo();
    checkAcc.displayInfo();
  }
}

o/p chai yasto aayecha:
Account type=Saving Id= 1 NameramBalance 20200.12
Account type=Checking Id= 1 NameramBalance 2800.0
Read Full Discussion Thread for this article