//Program to demonstrate single Inheritence
//Program by Ahlam Ansari
class BankAccount
{
private String ownersName;
private int accountNumber;
private float balance;
private int pinNumber;
public BankAccount(int anAccountNumber, String aName, float aBalance)
{
accountNumber = anAccountNumber;
ownersName = aName;
balance = aBalance;
}
public void deposit(float anAmount)
{
if (anAmount>0.0)
balance = balance + anAmount;
}
public void withdraw(float anAmount)
{
if ((anAmount>0.0) && (balance>anAmount))
balance = balance - anAmount;
}
public float getBalance()
{
return balance;
}
public void updateBalance(float aBalance)
{
balance= aBalance;
}
}
class SavingAccount extends BankAccount
{
private float saveLimit;
public SavingAccount(int anAccountNumber, String aName, float aLimit, float aBalance)
{
super(anAccountNumber, aName, aBalance);
saveLimit = aLimit;
}
public void withdraw(float anAmount)
{
float aBalance;
if ((anAmount>0.0) && (getBalance()>anAmount)&&(getBalance()-anAmount>=saveLimit))
{
aBalance = getBalance() - anAmount;
updateBalance(aBalance);
}
else
System.out.println("Cannot withdraw as balance is insufficient");
}
}
class MyAccount
{
public static void main(String ahlam[])
{
SavingAccount anAccount = new SavingAccount(8801, "Ahlam Ansari", 10000.0f , 50000.0f);
anAccount.deposit(57890.0f);
System.out.println("Your Current Balance is Rs." +anAccount.getBalance()+"/-");
anAccount.withdraw(11890.0f);
System.out.println("Your Current Balance is Rs." +anAccount.getBalance()+"/-");
}
}
/*
C:\Documents and Settings\AHLAM\My Documents\Google Drive\My Lectures\Fall\OOPM\
Programs>javac MyAccount.java
C:\Documents and Settings\AHLAM\My Documents\Google Drive\My Lectures\Fall\OOPM\
Programs>java MyAccount
Your Current Balance is Rs.107890.0/-
Your Current Balance is Rs.96000.0/-
C:\Documents and Settings\AHLAM\My Documents\Google Drive\My Lectures\Fall\OOPM\
Programs>
*/
//Program by Ahlam Ansari
class BankAccount
{
private String ownersName;
private int accountNumber;
private float balance;
private int pinNumber;
public BankAccount(int anAccountNumber, String aName, float aBalance)
{
accountNumber = anAccountNumber;
ownersName = aName;
balance = aBalance;
}
public void deposit(float anAmount)
{
if (anAmount>0.0)
balance = balance + anAmount;
}
public void withdraw(float anAmount)
{
if ((anAmount>0.0) && (balance>anAmount))
balance = balance - anAmount;
}
public float getBalance()
{
return balance;
}
public void updateBalance(float aBalance)
{
balance= aBalance;
}
}
class SavingAccount extends BankAccount
{
private float saveLimit;
public SavingAccount(int anAccountNumber, String aName, float aLimit, float aBalance)
{
super(anAccountNumber, aName, aBalance);
saveLimit = aLimit;
}
public void withdraw(float anAmount)
{
float aBalance;
if ((anAmount>0.0) && (getBalance()>anAmount)&&(getBalance()-anAmount>=saveLimit))
{
aBalance = getBalance() - anAmount;
updateBalance(aBalance);
}
else
System.out.println("Cannot withdraw as balance is insufficient");
}
}
class MyAccount
{
public static void main(String ahlam[])
{
SavingAccount anAccount = new SavingAccount(8801, "Ahlam Ansari", 10000.0f , 50000.0f);
anAccount.deposit(57890.0f);
System.out.println("Your Current Balance is Rs." +anAccount.getBalance()+"/-");
anAccount.withdraw(11890.0f);
System.out.println("Your Current Balance is Rs." +anAccount.getBalance()+"/-");
}
}
/*
C:\Documents and Settings\AHLAM\My Documents\Google Drive\My Lectures\Fall\OOPM\
Programs>javac MyAccount.java
C:\Documents and Settings\AHLAM\My Documents\Google Drive\My Lectures\Fall\OOPM\
Programs>java MyAccount
Your Current Balance is Rs.107890.0/-
Your Current Balance is Rs.96000.0/-
C:\Documents and Settings\AHLAM\My Documents\Google Drive\My Lectures\Fall\OOPM\
Programs>
*/
No comments:
Post a Comment