// Method to withdraw money // Parameters: // amount - the amount of money to be withdrawn public void Withdraw(int amount) { ScreenClear(); Screen.Items.Add("Please Wait..."); Screen.Refresh(); if (dataRace) // If a race condition can occur { if (!account.dataRaceDecrementBalance(amount)) // If the money could not be withdrawn { ScreenClear(); Screen.Items.Add("Insufficient funds"); // Tell the user that they do not have enough money MessageBank(account.getAccountNum() + " attempted to withdraw £" + amount); } else // If the money was withdrawn { DisplayMenuOptions(); // Enable the basic menu Screen.Items.Add("Withdrawing £" + amount); // Tell the user that their money is being withdrawn Screen.Items.Add("Race condition is possible"); Screen.Items.Add("Please check balance"); Console.WriteLine("£" + amount + " has been withdrawn"); MessageBank(account.getAccountNum() + " withdrew £" + amount + ". Their balance is now £" + account.getBalance()); } } else // If a race condition should not occur { if (!account.semaphoreDecrementBalance(amount)) // If the money could not be withdrawn { ScreenClear(); Screen.Items.Add("Insufficient funds"); // Tell the user that they do not have enough money MessageBank(account.getAccountNum() + " attempted to withdraw £" + amount); } else // If the money was withdrawn { DisplayMenuOptions(); // Enable the basic menu Screen.Items.Add("Withdrawing £" + amount); // Tell the user that their money is being withdrawn Screen.Items.Add("Race condition was avoided"); Console.WriteLine("£" + amount + " has been withdrawn"); MessageBank(account.getAccountNum() + " withdrew £" + amount + ". Their balance is now £" + account.getBalance()); } } }