public static bool ValidateWithdraw(double amount, double balance) { if (amount > balance) { SystemMessages.ShowMessage("Withdrawal amount should not be more than the current balance."); SystemMessages.ShowCommandMessage(); return(false); } else { if (amount < 300) { SystemMessages.ShowMessage("Unable to process transaction. 300 is minimum withdrawal amount"); SystemMessages.ShowCommandMessage(); return(false); } else if (amount > 10000) { SystemMessages.ShowMessage("Unable to process transaction. 10,000 is maximum withdrawal amount"); SystemMessages.ShowCommandMessage(); return(false); } } SystemMessages.ShowCommandMessage(); return(true); }
public static void LogTransactionDetails(double amount, double oldbalance, double newbalance, string action, string transdate) { if (action == "WITHDRAW") { Console.WriteLine("***************************"); Console.WriteLine("***************************"); Console.WriteLine("***************************"); Console.WriteLine("***************************"); Console.WriteLine("***************************"); Console.WriteLine("***************************"); Console.WriteLine(" "); Console.WriteLine(" "); Console.WriteLine("Withdrawal Details : "); Console.WriteLine(" "); Console.WriteLine("Before Transaction Balance = " + oldbalance.ToString()); Console.WriteLine("Withdrawal Amount = " + amount.ToString()); Console.WriteLine("Current Transaction Balance = " + newbalance.ToString()); Console.WriteLine("Date of Transaction = " + transdate.ToString()); Console.WriteLine(" "); Console.WriteLine(" "); Console.WriteLine("***************************"); Console.WriteLine("***************************"); Console.WriteLine("***************************"); Console.WriteLine("***************************"); Console.WriteLine("***************************"); Console.WriteLine("***************************"); } else { Console.WriteLine("***************************"); Console.WriteLine("***************************"); Console.WriteLine("***************************"); Console.WriteLine("***************************"); Console.WriteLine("***************************"); Console.WriteLine("***************************"); Console.WriteLine(" "); Console.WriteLine(" "); Console.WriteLine("Deposit Details : "); Console.WriteLine(" "); Console.WriteLine("Before Transaction Balance = " + oldbalance.ToString()); Console.WriteLine("Deposit Amount = " + amount.ToString()); Console.WriteLine("Current Transaction Balance = " + newbalance.ToString()); Console.WriteLine("Transaction Date = " + transdate.ToString()); Console.WriteLine(" "); Console.WriteLine(" "); Console.WriteLine("***************************"); Console.WriteLine("***************************"); Console.WriteLine("***************************"); Console.WriteLine("***************************"); Console.WriteLine("***************************"); Console.WriteLine("***************************"); } SystemMessages.ShowCommandMessage(); Console.ReadLine(); }
static void Main(string[] args) { SystemMessages.IntroductionMessage(); while (IsExit == false) { string input = Console.ReadLine(); string[] inputArray = input.Trim().Split(new Char[] { ' ', '\n' }); String cmd = ""; String amount_enter = ""; for (int i = 0; i < inputArray.Length; i++) { if (i == 0) { cmd = inputArray[0].ToString(); } else { amount_enter = inputArray[1].ToString(); } } Bank bank = new Bank(); ICommand cmdWithdraw = new Commands.WithdrawCommand(bank); ICommand cmdDeposite = new Commands.DepositCommand(bank); Invoker invoker = new Invoker(); if (cmd == "WITHDRAW") { invoker.amount = Convert.ToDouble(amount_enter); invoker.StoreAndExecute(cmdWithdraw); } else if (cmd == "DEPOSIT") { invoker.amount = Convert.ToDouble(amount_enter); invoker.StoreAndExecute(cmdDeposite); } else { Console.WriteLine("INVALID COMMAND"); Console.WriteLine("PLEASE ENTER COMMAND <DEPOSIT> OR <WITHDRAW>"); } } //end while }
public static void Deposit(double amount) { bool isValidDepositTransaction = ValidationDecorator.ValidateDeposit(amount, _balance); if (isValidDepositTransaction == false) { SystemMessages.ExitApp(); } else { double oldbalance = _balance; double newbalance = _balance + amount; _balance = _balance + amount; LoggingDecorator.LogTransactionDetails(amount, oldbalance, newbalance, "DEPOSIT", DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString()); } }
public static void Withdraw(double amount) { bool isValidWithdrawalTransaction = ValidationDecorator.ValidateWithdraw(amount, _balance); if (isValidWithdrawalTransaction == false) { SystemMessages.ExitApp(); } else { double oldbalance = _balance; double newbalance = _balance - amount; _balance = _balance - amount; LoggingDecorator.LogTransactionDetails(amount, oldbalance, newbalance, "WITHDRAW", DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString()); } }
public static bool ValidateDeposit(double amount, double balance) { if (amount < 1000) { SystemMessages.ShowMessage("Unable to process transaction. Minimum deposit amount is 1,000"); SystemMessages.ShowCommandMessage(); return(false); } else if (amount > 50000) { SystemMessages.ShowMessage("Unable to process transaction. Maximum deposit amount is 50,000"); SystemMessages.ShowCommandMessage(); return(false); } SystemMessages.ShowCommandMessage(); return(true); }