public static void transfer(BankAccount from, BankAccount to) { Console.WriteLine("Enter amount of money:"); double sum = double.Parse(Console.ReadLine()); if (from.Withdraw(sum)) { to.Deposit(sum); } else { Console.WriteLine("\\nThere isn't enough money!"); } }
private static void transferMoney(BankAccount fromAccount, BankAccount toAccount) { Console.WriteLine("Enter amount of money"); double amount = double.Parse(Console.ReadLine()); //Do we have enough money in our wallet? if (fromAccount.Withdraw(amount)) { toAccount.Desposit(amount); } else { Console.WriteLine("\nThere isn't enough money to complete this transaction\n"); } }
private void btnTest_Click(object sender, EventArgs e) { // create a display string variable and initialize to an empty string string display = ""; // create two bank account objects using both constructors - with valid data BankAccount acc1 = new BankAccount(1, 43); BankAccount acc2 = new BankAccount(23, 24, "Mark Johns"); // test one of the objects - get accessors --> add output to display string display += "Name: " + acc1.ClientName + "\nAccount Number: " + acc1.AccNumber + "\nDate Opened: " + acc1.OpenTime + "\nBalance: " + acc1.Balance; // test one of the objects - set accessors --> add output to display string acc1.ClientName = "Jones Jr"; display += "\n\nName Change: " + acc1.ClientName; // test one of the objects - methods --> add output to display string acc1.Deposit(1000); display += "\n\nDesposit $1000 - New Balance: " + acc1.Balance; acc1.Withdraw(23); display += "\nWithdraw $23 - New Balance: " + acc1.Balance; // show display string to user - use bank name in caption of message box MessageBox.Show(display, BankAccount.BankName); /*****************************Next Test*********************************/ // reset display string to empty string display = ""; // create one account using the 3 parameter constructor - invalid name BankAccount acc3 = new BankAccount(123445, 234, ""); // use get accessor to check name --> add output to display string display += ""; // use set accessor to set invalid name --> add output to display string acc3.ClientName = ""; display += "\nName: " + acc3.ClientName; // use set accessor to set valid name --> add output to display string acc3.ClientName = ""; display += "\nName: " + acc3.ClientName; // show display sgtring to user - use bank name in caption of message box MessageBox.Show(display, BankAccount.BankName); }
static void Main(string[] args) { BankAccount firstAccount; firstAccount = new BankAccount(); firstAccount.accountNumber = 10000001; firstAccount.Deposit(3000.00); Console.WriteLine("Acount {0} has balance {1}", firstAccount.accountNumber, firstAccount.Balance); Console.WriteLine(firstAccount.Withdraw(300)); Console.WriteLine(firstAccount.Balance); Console.ReadLine(); }
static void Main(string[] args) { var account = new BankAccount(); account.ID = 1; account.Balance = 15; account.Deposit(5); account.Withdraw(15); Console.WriteLine(account.ToString()); var person = new Person(); person.Name = "Ivan"; person.Age = 10; person.accounts.Add(account); Console.WriteLine(person.GetBalance()); }
static void Main() { var personA = new Person("John", 22); var acc_1 = new BankAccount(); var acc_2 = new BankAccount(); var accounts = new List <BankAccount>(); acc_1.Deposit(250); acc_1.Withdraw(50); acc_2.Deposit(22.506m); accounts.Add(acc_1); accounts.Add(acc_2); var personB = new Person("Jane", 31, accounts); Console.WriteLine(personA.GetBalance()); Console.WriteLine(personB.GetBalance()); }
public void TransferMoney(BankAccount sendingAccount, BankAccount receivingAccount) { double sendingAmount; if (double.TryParse(amountEntry.Text, out sendingAmount)) { if (sendingAccount.Withdraw(sendingAmount)) { receivingAccount.Deposit(sendingAmount); UpdateLabels(); } else { DisplayAlert("Out of money", "Cannot transfer amount.", "Okay"); } } else { DisplayAlert("Invalid Entry", "Please try again with valid entry.", "Okay"); } }
private static void Withdraw(string[] commands, Dictionary <int, BankAccount> accounts, int id) { if (accounts.ContainsKey(id)) { BankAccount acc = accounts[id]; if (accounts[id].Balance < decimal.Parse(commands[2])) { Console.WriteLine("Insufficient balance"); } else { acc.Id = id; accounts[id].Balance = acc.Withdraw(int.Parse(commands[2])); } } else { Console.WriteLine("Account does not exist"); } }
static void Main() { List <BankAccount> accounts = new List <BankAccount>(); string[] input; while ((input = Console.ReadLine().Split())[0] != "End") { int id = int.Parse(input[1]); string command = input[0].ToLower(); BankAccount currentAcc = accounts.FirstOrDefault(x => x.Id == id); if (currentAcc is null && command != "create") { Console.WriteLine("Account does not exist"); continue; } switch (input[0].ToLower()) { case "create": if (currentAcc is null) { accounts.Add(new BankAccount(id)); break; } Console.WriteLine("Account already exist"); break; case "deposit": currentAcc.Deposit(decimal.Parse(input[2])); break; case "withdraw": currentAcc.Withdraw(decimal.Parse(input[2])); break; case "print": Console.WriteLine(currentAcc); break; } } }
private static void Withdraw(string[] cmdArgs, Dictionary <int, BankAccount> accounts) { int id = int.Parse(cmdArgs[1]); decimal amount = decimal.Parse(cmdArgs[2]); if (accounts.ContainsKey(id)) { BankAccount acc = accounts.FirstOrDefault(ba => ba.Key == id).Value; if (acc.Balance < amount) { Console.WriteLine("Insufficient balance"); } else { acc.Withdraw(amount); } } else { Console.WriteLine("Account does not exist"); } }
static void Main(string[] args) { BankAccount b1 = new BankAccount("A1234", 250); Console.WriteLine(b1); BankAccount b2 = new BankAccount("B45646", 7500); Console.WriteLine(b2); Console.WriteLine(); b1.Deposit(500); Console.WriteLine("Depositing 500 into account - {0}, new balance now is: {1:0.00}", b1.AccountNumber, b1.Balance); b2.Deposit(975); Console.WriteLine("Depositing 975 into account - {0}, new balance now is: {1:0.00}", b2.AccountNumber, b2.Balance); Console.WriteLine(); Console.WriteLine(b1.Withdraw(200)); Console.WriteLine(b2.Withdraw(9500)); }
static void Main(string[] args) { var acc = new BankAccount(); acc.Id = 1; acc.Deposit(15); acc.Withdraw(10); Console.WriteLine(acc); //var data = new Dictionary<int, BankAccount>(); //while (true) //{ // string[] tokens = Console.ReadLine().Split(); // if (tokens[0] !="End") // { // switch (tokens[0]) // { // case "Create": // Create(tokens, data); // break; // case "Deposit": // Deposit(tokens, data); // break; // case "Withdraw": // Withdraw(tokens, data); // break; // case "Print": // Print(tokens, data); // break; // default: // break; // } // } // else // { // break; // } //} }
public static void Main() { var account = new BankAccount(); var customers = new List <Thread>(); var random = new Random(4711); for (int count = 0; count < Customers; count++) { var credit = random.Next(StartBudget); customers.Add(new Thread(() => { for (var k = 0; k < Transactions; k++) { account.Deposit(credit); if (!account.Withdraw(credit)) { throw new Exception("Race condition"); } } })); } account.Deposit(StartBudget); var watch = Stopwatch.StartNew(); foreach (var customer in customers) { customer.Start(); } foreach (var customer in customers) { customer.Join(); } Console.WriteLine($"Total time {watch.ElapsedMilliseconds} ms"); if (account.Balance != StartBudget) { throw new Exception($"Incorrect final balance: {account.Balance}"); } }
static void Main(string[] args) { BankAccount bankAccount = new BankAccount(5000, 2.0m); bankAccount.Withdraw(-1); }
public static void Main() { List <BankAccount> accounts = new List <BankAccount>(); while (true) { string[] command = Console.ReadLine().Split(); if (command[0] == "Create") { int id = int.Parse(command[1]); if (!accounts.Any(x => x.Id == id)) { accounts.Add(new BankAccount(id)); } else { Console.WriteLine("Account already exists"); } } else if (command[0] == "Deposit") { int id = int.Parse(command[1]); decimal amount = decimal.Parse(command[2]); BankAccount requested = accounts.FirstOrDefault(x => x.Id == id); if (requested == null) { Console.WriteLine("Account does not exist"); } else { requested.Deposit(amount); } } else if (command[0] == "Withdraw") { int id = int.Parse(command[1]); decimal amount = decimal.Parse(command[2]); BankAccount requested = accounts.FirstOrDefault(x => x.Id == id); if (requested == null) { Console.WriteLine("Account does not exist"); } else if (amount > requested.Balance) { Console.WriteLine("Insufficient balance"); } else { requested.Withdraw(amount); } } else if (command[0] == "Print") { int id = int.Parse(command[1]); BankAccount requested = accounts.FirstOrDefault(x => x.Id == id); if (requested == null) { Console.WriteLine("Account does not exist"); } else { Console.WriteLine(requested.ToString()); } } else if (command[0] == "End") { return; } } }