static void Main(string[] args) { #region code from previous classes (towards end of 12/6) commented out /* * var account = BankFactory.CreateAccount("Joba's Checcking", 500); * ////Create an instance of an Account == object * //var account = new Account(); * ////account.AccountNumber = 123; * //account.Name = "Joba's Checking"; * ////account.Balance = 100000000; * //account.Deposit(500); * ////Console.WriteLine(account.Balance); * Console.WriteLine( * "Name: {0}, Account Number: {1}, Account Balance: {2:c}", * account.Name, account.AccountNumber, account.Balance * ); * * //create SavingsAccount * var savingsAccount = BankFactory.CreateAccount("Joba's Savings", 10); * //var savingsAccount = new Account(); * ////Account savingsAccount = new Account(); //this is the old style * //savingsAccount.Name = "Joba's savings"; * //savingsAccount.Deposit(10); * * //Exception handling * try * { * savingsAccount.Withdraw(100); * } * catch(ArgumentException exceptionMessage) * { * Console.WriteLine("Oops something went wrong : {0}", * exceptionMessage.Message); * } * catch (Exception) //to catch all exceptions not specifically handled * { * Console.WriteLine("Something went wrong"); * } * Console.WriteLine( * "Name: {0}, Account Number: {1}, Account Balance: {2:c}", * savingsAccount.Name, savingsAccount.AccountNumber, savingsAccount.Balance * ); */ #endregion Console.WriteLine("*** Welcome to Bedrock Bank ***"); Console.Write("Please login with SSN: "); var ssn = Console.ReadLine(); int convertedSSN; if (int.TryParse(ssn, out convertedSSN) == true) { var accounts = BankFactory.GetAllAccountsBySSN(convertedSSN); if (accounts == null) { Console.WriteLine("No Accounts"); } } }
static void Main(string[] args) { bool success = false; short attempts = 1; Console.WriteLine("*************Welcome to Bedrock Bank**********"); try { while (!success && attempts++ < 4) { Console.Write("Please enter your ssn(without the dashes): "); //Get string ssn var ssn = Console.ReadLine(); int convertedSSN; //Converting the SSN into an integer if (int.TryParse(ssn, out convertedSSN) == true) { //if conversion is successful, get the accounts for ssn var accounts = BankFactory.GetAllAccountsBySSN(convertedSSN); for (int i = 0; i < accounts.Length; i++) { //enumerate through the list of accounts if (!success) { //Mark it as a successful attempt success = true; } //print a meaningful index to the user Console.WriteLine("{0}. Name: {1}", i + 1, accounts[i].Name); } if (success) { //Let's ask the user for the account to pull up the details Console.WriteLine("Type 0 to exit"); while (true) { Console.Write("Please select an account number: "); var accountIndex = Console.ReadLine(); int convertedAccountIndex; if (int.TryParse(accountIndex, out convertedAccountIndex) == true) { if (convertedAccountIndex == 0) { break; } else if (convertedAccountIndex < 0 || convertedAccountIndex > accounts.Length) { continue; } var account = accounts[convertedAccountIndex - 1]; Console.WriteLine("Account number: {0}, Name: {1}, Balance: {2:c}", account.AccountNumber, account.Name, account.Balance); } } } } } } catch (Exception) { Console.WriteLine("Sorry, system is down. Please try again later."); } }