public Boolean execute(Account acc, Bank bank, int amount) { if (amount > (acc.GetBalance() * 0.3)) { return(false); } else if (amount <= 0) { throw new System.ArgumentException("Invalid requested amount."); } else { acc.SetBalance(acc.GetBalance() + amount); bank.AvailableLoan = bank.AvailableLoan - amount; return(true); } }
//public Transaction() : base (OperationType.Type type , string desc) //{ // super(type, desc); // this.transferAmount = amount; //} public void execute(Account sender, Account receiver, int amount) { if (amount > sender.GetBalance()) { throw new System.ArgumentException("Not enough balance."); } else if (amount <= 0) { throw new System.ArgumentException("Negative amount to transfer."); } sender.SetBalance(sender.GetBalance() - amount); receiver.SetBalance(receiver.GetBalance() + amount); //sender.balance = sender.balance - amount; //receiver.balance = receiver.balance + amount; Console.WriteLine("Amount transferred."); }
public void Deposit(int amount) { if (this.GetDebtBalance() > 0) { if (amount >= this.GetDebtBalance()) { int difference = amount - this.GetDebtBalance(); this.SetDebtBalance(0); account.SetBalance(difference); } else { this.SetDebtBalance(this.GetDebtBalance() - amount); } } else { account.Deposit(amount); } }
public override void Handle(Account acc) { acc.SetBalance(acc.GetBalance() + 10); }