Need help in Java using interface -


  1. i having problem in getting 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 me ,i 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 initialise loan account balance =(accbal=20000.00;) have tried accbal=20000.00 in sub class

if following practice , tdd if cannot because not support it, write test, write code, refactor repeat.

do not afraid throw code away if not fit purpose, 1 thing split classes separate files. makes easier follow going on.

as setting initial balance, set in constructor each class

public class loanaccount implements account {

  public loanaccount(double initialbalance)   {       this.accbalance = initialbalance;   } 

}


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -