java - Bank cash (deposit and withdrawal) - for educational purposes -


i have problem on program. , problem cannot minus withdrawal deposit value.

code below:

public static void main(string[] args) {     double cash;     boolean more = true;      deposite dep = new deposite();     withdraw = new withdraw();      while (more) {         cash = double.parsedouble(joptionpane.showinputdialog("cash deposite"));         dep.deposite(cash);         dep.print();            int con = joptionpane.yes_no_option;      int con1 = joptionpane.showconfirmdialog(null, "do want more deposites?","depository",con);          if (con1 == 1) {             int con3 = joptionpane.showconfirmdialog(null, "withdraw now?","withdrawal",con);             if (con3 == 0) {                 cash = double.parsedouble(joptionpane.showinputdialog("cash withdraw"));                 with.withdraw(cash);                 with.print();                 system.out.println("thanks");             }         }       } } 

and subclass have made functions

public class deposite {     private double depcash;          public double deposite(double cash){             depcash += cash;              return this.depcash;         }         void print(){             system.out.printf("your deposite $%5.2f",depcash);             system.out.println(" ");         } } 

and withdrawal class. inherit it. still dont know how works.

code below :

public class withdraw extends deposite {     double cash;      public double withdraw(double withdraw){         super.deposite(withdraw);         cash -=withdraw;         return cash;     }     void print (){         system.out.printf("you cash balance $%5.2f",cash);         system.out.println(" ");     } } 

  • first of all, never name methods object constructors public double deposite(double cash).
  • secondly, why withdraw class extend deposite? there reason this?

that how implement banking logic:

  bank bank = new bank();   account account = new account(123.50);   bank.execute(account, new deposit(), 1);   bank.execute(account, new withdraw(), 13.50);       private static interface operation {         double apply(account account, double value);     }      private static class deposit implements operation {          @override         public double apply(account account, double value) {             return account.getmoney() - value;         }     }      private static class withdraw implements operation {          @override         public double apply(account account, double value) {             return account.getmoney() + value;         }     }      private static class account {         private final double money;          public account(double money) {             this.money = money;         }          public double getmoney() {             return money;         }      }      private static class bank {         public void execute(account account, operation operation, double amount) {             operation.apply(account, amount);         }     } 

Comments

Popular posts from this blog

What is happening when Matlab is starting a "parallel pool"? -

angular - DownloadURL return null in below code -

php - Cannot override Laravel Spark authentication with own implementation -