using System; using System.Collections.Generic; using System.Linq; using System.Text; using MyExtensionLibrary; namespace BankSystem { class Program { static void Main(string[] args) { Exercise1Test(); Exercise2Test(); Exercise3Test(); Console.ReadLine(); } private static void Exercise1Test() { Console.WriteLine("Exercise 1 test"); Console.WriteLine("--------------------------------------------"); // Create some objects using object initializer syntax. BankAccount acc1 = new BankAccount { AccountHolder = "John", Balance = 1000 }; BankAccount acc2 = new BankAccount { AccountHolder = "Mary", Balance = 2000 }; BankAccount acc3 = new BankAccount { AccountHolder = "Sara", Balance = 3000 }; // Create a collection using collection initializer syntax. List accounts = new List { new BankAccount { AccountHolder = "Huey", Balance = 4000 }, new BankAccount { AccountHolder = "Lewey", Balance = 5000 }, new BankAccount { AccountHolder = "Dewey" } // Deliberately haven't set balance, defaults to 0. }; foreach (BankAccount acc in accounts) { Console.WriteLine("{0}", acc); } } private static void Exercise2Test() { Console.WriteLine("\nExercise 2 test"); Console.WriteLine("--------------------------------------------"); // Create a Bank and add some BankAccounts. Bank bank = new Bank(); bank[123] = new BankAccount { AccountHolder = "John", Balance = 1000 }; bank[456] = new BankAccount { AccountHolder = "Mary", Balance = 2000 }; bank[789] = new BankAccount { AccountHolder = "Sara", Balance = 3000 }; // Create an object of anonymous type. var info = new { NumAccs = bank.NumberOfAccounts, LastAccBalance = bank[789].Balance, Timestamp = DateTime.Now }; // Display values of object of anonymous type. Console.WriteLine("Number of accounts: {0}", info.NumAccs); Console.WriteLine("Balance of last account: {0}", info.LastAccBalance); Console.WriteLine("Timestamp: {0}", info.Timestamp); Console.WriteLine("Anonymous type info: {0}", info.GetType()); } private static void Exercise3Test() { Console.WriteLine("\nExercise 3 test"); Console.WriteLine("--------------------------------------------"); Console.Write("Enter a number: "); double num = double.Parse(Console.ReadLine()); if (num.InRange(10, 30)) Console.WriteLine("{0} is in the range [10,30].", num); else Console.WriteLine("{0} is not in the range [10,30].", num); Console.Write("Enter a string: "); string str = Console.ReadLine(); if (str.IsStrongPassword()) Console.WriteLine("{0} is a strong password.", str); else Console.WriteLine("{0} is a weak password.", str); } } }