java - i want to update my current balance -
i can subtract 85000. cuz value initialized. example lets 2000 , subtracted 85000 , gives 83000. problem if second time , withdrawal value subtract 85000 not 83000.how can update value .??
public class withdrawal { private double amount; private double currentbalance=85000.00; double total; public withdrawal(double amount1,double currentbalance) { this.currentbalance = currentbalance; this.amount = amount1; } public withdrawal(double currentbalance){ this.currentbalance = currentbalance; } public withdrawal(){ } public void setamount(double amount1){ this.amount =amount1; } public double getamount(){ return amount; } public void setcurrentbalance(double currentbalance) { this.currentbalance =currentbalance; } public double getcurrentbalance() { return currentbalance; } public double gettotalamount(){ total= getcurrentbalance()- getamount(); return total; } }
i think you're little confused on how objects stored.
you're correct in thinking withdrawal have it's own object, wouldn't used way think should be.
firstly, need account object hold money (a withdrawal doesn't hold money, it's withdrawal!)
an account can simple:
public class account { double balance; public void withdraw(double amount) { this.balance -= amount; } public double getbalance() { return this.balance; } } the reason withdrawal object perhaps store dates , amount taken?
Comments
Post a Comment