private static void TestWithdrawal() { List <BankAccount> accounts = new List <BankAccount>(); BankAccount accountA = new CreditBankAccount("USD", -1000); accountA.Deposit(500); BankAccount accountB = new CurrentBankAccount("USD"); accountB.Deposit(1200); accounts.Add(accountA); accounts.Add(accountB); while (true) { Console.WriteLine("********************"); Console.WriteLine("Please choose account:"); for (int i = 0; i < accounts.Count; i++) { Console.WriteLine("{0}: {1}", i + 1, accounts[i]); } if (int.TryParse(Console.ReadLine(), out int selectedIndex) && accounts.Count >= selectedIndex && selectedIndex > 0 ) { BankAccount selectedAccount = accounts[selectedIndex - 1]; Console.WriteLine("Select the amount to withdraw from this account: {0}", selectedAccount); if (int.TryParse(Console.ReadLine(), out int amount)) { selectedAccount.Withdraw(amount); XmlSerializer serializer = new XmlSerializer(typeof(List <BankAccount>)); TextWriter writer = new StreamWriter("c:\\test\\bankaccounts.xml"); serializer.Serialize(writer, accounts); writer.Close(); Console.WriteLine("Account after withdraw: {0}", selectedAccount); } } else { Console.WriteLine("Error. Please select one of the above"); } } }
private static List <Customer> GenerateCustomers() { List <string> names = new List <string> { "John Lennon", "Paul McCartney", "Christiano Ronaldo", "Firas Hamdan" }; Random rnd = new Random(); List <Customer> customers = new List <Customer>(); int id = 1; foreach (string name in names) { Customer customer = new Customer(); customer.Id = id; customer.FullName = name; customer.Accounts = new List <BankAccount>(); customers.Add(customer); int numberOfAccounts = rnd.Next(2, 5); for (int i = 0; i < numberOfAccounts; i++) { var isCredit = rnd.Next(0, 10) % 2 == 0; var isDollar = rnd.Next(0, 10) % 2 == 0; if (isCredit) { var limit = rnd.Next(500, 1300) * (isDollar ? 1 : 1500); var bankAccount = new CreditBankAccount(isDollar ? "USD" : "LBP", limit); customer.Accounts.Add(bankAccount); } else { var bankAccount = new CurrentBankAccount(isDollar ? "USD" : "LBP"); customer.Accounts.Add(bankAccount); } } id++; } return(customers); }
public static void Main(string[] args) { BankAccount savingAccount = new SavingBankAccount("Adittya", "18386933"); BankAccount currentAccount = new CurrentBankAccount("Arup", "183869331"); savingAccount.Deposit(40000); savingAccount.Withdraw(1000); savingAccount.Withdraw(1000); savingAccount.Withdraw(1000); Console.WriteLine(); currentAccount.Deposit(190000); currentAccount.Withdraw(1000); Console.ReadLine(); }
private void Button_Click(object sender, RoutedEventArgs e) { var selectedAccount = (string)AccountTypeCombo.SelectedItem; if (selectedAccount == "Current") { BankAccount acc = new CurrentBankAccount(this.CurrerncyTxt.Text); _accounts.Add(acc); //this.AccountsList.ItemsSource = _accounts; } else if (selectedAccount == "Credit") { BankAccount acc = new CreditBankAccount(this.CurrerncyTxt.Text, int.Parse(LimitTxt.Text)); _accounts.Add(acc); //this.AccountsList.ItemsSource = _accounts; } }