- I am having a problem in getting the o/p
Depositing amount.....10000.0
Withdrawing amount.....4999.0
Savings Account Balance is:5001.0Rs
Depositing amount.....9000.0
Loan Account Balance is:11000.0Rs
Withdrawing amount.....5000.0
Loan Account Balance is:16000.0Rs
please help me ,i am a beginner:
package interfaces;
interface Account
{
double accBal;
void deposit(double amt);
void withdraw(double amt);
void printBalance();
}
class SavingsAccount implements Account
{
public void deposit(double amt)
{
System.out.println("Depositing amount....."+amt);
accBal = accBal + amt;
}
public void withdraw(double amt)
{
System.out.println("Withdrawing amount....."+amt);
accBal=accBal - amt;
}
public void printBalance()
{
System.out.println("Savings Account Balance is:" +accBal+ "Rs");
}
}
class LoanAccount implements Account
{
public void deposit(double amt)
{
System.out.println("Depositing amount....."+amt);
accBal=accBal - amt;
}
public void withdraw(double amt)
{
System.out.println("Withdrawing amount....."+amt);
accBal=accBal + amt;
}
public void printBalance()
{
System.out.println("Loan Account Balance is:" +accBal+ "Rs");
}
}
public class TestAccount {
public static void main(String[] args)
{
Account acc1;
acc1 = new SavingsAccount();
acc1.deposit(10000);
acc1.withdraw(4999);
acc1.printBalance();
acc1 = new LoanAccount();
acc1.deposit(9000);
acc1.printBalance();
acc1.withdraw(5000);
acc1.printBalance();
}
}
need to initialise loan account balance =(accBal=20000.00;) i have tried accbal=20000.00 in sub class