Esempio n. 1
0
        static void Main(string[] args)
        {
            Account ac01 = new Account("efudd", 345.00M, "efudd1", "Elmer Fudd");
            Account ac02 = new Account("bbunny", 1722.12M, "bbunny1", "Bugs Bunny");
            Account ac03 = new Account("tbird", 45.44M, "tbird1", "Tweety Bird");
            Bank    bank = new Bank();

            bank.Add(ac01);
            bank.Add(ac02);
            bank.Add(ac03);
            string userInput = "";
            bool   loopFlag  = true;



            while (loopFlag)
            {
                Console.Clear();
                System.Console.WriteLine("Welcome to WB Bank");
                System.Console.WriteLine("(L)ogin (Q)uit");
                userInput = Console.ReadLine().ToLower();
                if (userInput == "q")
                {
                    System.Console.WriteLine("Have a nice day, Goodbye!");
                    loopFlag = false;
                }
                else if (userInput == "l")
                {
                    System.Console.WriteLine("Please enter your username");
                    string username = Console.ReadLine();
                    System.Console.WriteLine("Please enter your password");
                    string password = Console.ReadLine();

                    if (bank.Login(username, password))
                    {
                        bool    loggedIn      = true;
                        string  userSelection = "";
                        decimal userMoney     = 0.00M;
                        decimal accChange     = 00.00M;
                        //String receipt = String.Format("Total change to your account  ${0}\n" +
                        // "Your current Account balance is ${1}", accChange, bank.activeUser.Balance);
                        String receipt = String.Format("Total change to your account  ${0}\n" +
                                                       "Your current " + bank, accChange);

                        while (loggedIn)
                        {
                            Console.Clear();
                            System.Console.WriteLine("Welcome. Please select from the following.");
                            System.Console.WriteLine("(W)ithdraw - (D)eposit - (B)alance - (L)ogout");
                            userSelection = Console.ReadLine().ToLower();


                            if (userSelection == "l")
                            {
                                loggedIn = false;
                                System.Console.WriteLine("Session ended. Here is your Transaction history for this session\n\n" + receipt + "\n\nPress any key to return to main menu.");
                                Console.ReadKey();
                            }

                            else if (userSelection == "b")
                            {
                                System.Console.WriteLine(bank);
                                Console.ReadKey();
                            }

                            else if (userSelection == "d")
                            {
                                System.Console.WriteLine("Enter deposit amount");
                                userMoney = Decimal.Parse(Console.ReadLine());
                                bank.activeUser.Balance += userMoney;
                                System.Console.WriteLine("Deposited $" + userMoney + "\nPress any key to continue");
                                receipt += String.Format("\nDeposit:\t${0}", userMoney);
                                Console.ReadKey();
                            }

                            else if (userSelection == "w")
                            {
                                System.Console.WriteLine("Enter withdrawl amount");
                                userMoney = Decimal.Parse(Console.ReadLine());
                                bank.activeUser.Balance -= userMoney;
                                System.Console.WriteLine("Withdrew $" + userMoney + "\nPress any key to continue");
                                receipt += String.Format("\nWithdrawl:\t${0}", userMoney);
                                Console.ReadKey();
                            }

                            else
                            {
                                System.Console.WriteLine("Sorry, input not recognized. \nPress any key to continue.");
                            }
                        }
                    }

                    else
                    {
                        System.Console.WriteLine("Sorry, account doesn't exist or information is incorect");
                        Console.ReadKey();
                    }
                }
                else
                {
                    System.Console.WriteLine("Sorry, I didn't recognize that input \n Press any key to continue.");
                    Console.ReadKey();
                }
            }
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            Console.WriteLine("*******");
            Console.WriteLine("Welcome to my bank");
            Console.WriteLine("*******");
            while (true)
            {
                Console.WriteLine("Please choose an option below:");
                Console.WriteLine("0. Exit");
                Console.WriteLine("1.Create an account");
                Console.WriteLine("2. Deposit");
                Console.WriteLine("3.Withdraw");
                Console.WriteLine("4.Print all accounts");
                Console.WriteLine("5.Print all transaction");

                var choice = Console.ReadLine();
                switch (choice)
                {
                case "0":
                    return;

                case "1":
                    Console.Write("Email Address:");
                    var emailAddress = Console.ReadLine();
                    Console.Write("Account type:");
                    var accountTypes = Enum.GetNames(typeof(TypeOfAccount));
                    for (int i = 0; i < accountTypes.Length; i++)
                    {
                        Console.WriteLine($"{i}.{accountTypes[i]}");
                    }
                    var accountType = (TypeOfAccount)Enum.Parse(typeof(TypeOfAccount), Console.ReadLine());
                    Console.Write("Amount to deposit:");
                    var amount  = Convert.ToDecimal(Console.ReadLine());
                    var account = Bank.CreateAccount(emailAddress, accountType, amount);
                    Console.WriteLine($"AN:{account.AccountNumber}, AT:{account.AccountType}, Balance:{account.Balance:C},Created Date:{account.CreatedDate}");
                    break;

                case "2":
                    PrintAllAccounts();
                    try {
                        Console.Write("Account number:");
                        var aNumber = Convert.ToInt32(Console.ReadLine());
                        Console.Write("Amount to deposit");
                        amount = Convert.ToDecimal(Console.ReadLine());
                        Bank.Deposit(aNumber, amount);
                        Console.WriteLine("Deposit was Successful!");
                    }
                    catch (FormatException)
                    {
                        Console.WriteLine("Either the account number or amount is invalid");
                    }
                    catch (OverflowException)
                    {
                        Console.WriteLine("Either the account number or the amount is beyond the range.");
                    }
                    catch (ArgumentOutOfRangeException ax)
                    {
                        Console.WriteLine(ax.Message);
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("Oops!Try again");
                    }

                    break;

                case "3":
                    PrintAllAccounts();
                    try
                    {
                        Console.Write("Account number:");
                        var aNumber = Convert.ToInt32(Console.ReadLine());
                        Console.Write("Amount to withdra");
                        amount = Convert.ToDecimal(Console.ReadLine());
                        Bank.Withdraw(aNumber, amount);
                        Console.WriteLine("Withraw was Successful!");
                    }
                    catch (ArgumentOutOfRangeException ax)
                    {
                        Console.WriteLine(ax.Message);
                    }

                    break;

                case "4":
                    PrintAllAccounts();
                    break;

                case "5":
                    PrintAllAccounts();
                    Console.Write("Account number:");
                    var accountNumber = Convert.ToInt32(Console.ReadLine());
                    var transactions  = Bank.GetAllTransactions(accountNumber);
                    foreach (var tran in transactions)
                    {
                        Console.WriteLine($"Id:{tran.TransactionId}, Date:{tran.TransactionId},Type:{tran.Amount},Description:{tran.Description}");
                    }

                    break;

                default:
                    break;
                }
            }
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            Bank bank = new Bank();

            bank.StartBankApp();
        }
Esempio n. 4
0
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to the Banking Application");
            while (true)
            {
                Console.WriteLine("0 - Exit");
                Console.WriteLine("1 - Create New Account");
                Console.WriteLine("2 - Deposit");
                Console.WriteLine("3 - Withdraw");
                Console.WriteLine("4 - Print All Accounts");
                Console.WriteLine("5 - Print All Transactions");

                Console.Write("Select Option: ");
                var selection = Console.ReadLine();

                switch (selection)
                {
                case "0":
                    Console.WriteLine("Thank you for using our banking application!");
                    return;

                case "1":
                    Console.Write("Email Address: ");
                    var emailAddress = Console.ReadLine();
                    Console.Write("Account Name: ");
                    var accountName = Console.ReadLine();

                    Console.WriteLine("Select Account Type:");
                    var accountTypes = Enum.GetNames(typeof(AccountTypes));
                    for (int i = 0; i < accountTypes.Length; i++)
                    {
                        Console.WriteLine($"\t{i} - {accountTypes[i]}");
                    }
                    var accountType = Convert.ToInt32(Console.ReadLine());

                    Console.Write("Initial Deposit: ");
                    var initialDeposit = Convert.ToDecimal(Console.ReadLine());

                    var myAccount = Bank.CreateAccount(emailAddress, accountName, (AccountTypes)accountType, initialDeposit);

                    Console.WriteLine($"Account Number: {myAccount.AccountNumber} |" +
                                      $" Account Name: {myAccount.AccountName} |" +
                                      $" Account Type: {myAccount.AccountType} |" +
                                      $" Email: {myAccount.EmailAddress} |" +
                                      $" Balance: {myAccount.AccountBalance:C}");
                    break;

                case "2":
                    //Deposit
                    PrintAllAccounts();
                    Console.Write("Account Number: ");
                    var accountNumber = Convert.ToInt32(Console.ReadLine());
                    Console.Write("Ammount to Deposit: ");
                    var amount = Convert.ToDecimal(Console.ReadLine());
                    Bank.Deposit(accountNumber, amount);
                    Console.WriteLine("Deposit Successful");
                    break;

                case "3":
                    PrintAllAccounts();
                    Console.Write("Account Number: ");
                    accountNumber = Convert.ToInt32(Console.ReadLine());
                    Console.Write("Ammount to Withdraw: ");
                    amount = Convert.ToDecimal(Console.ReadLine());
                    Bank.Withdraw(accountNumber, amount);
                    Console.WriteLine("Deposit Successful");
                    break;

                case "4":
                    //Print all accounts
                    PrintAllAccounts();
                    break;

                case "5":
                    PrintAllAccounts();
                    Console.Write("Account Number: ");
                    accountNumber = Convert.ToInt32(Console.ReadLine());
                    var transactions = Bank.GetTransactionsByAccountNumber(accountNumber);
                    foreach (var transaction in transactions)
                    {
                        Console.WriteLine($"Trans Type: {transaction.TransactionType} | Trans Date: {transaction.TransactionDate} | Trans Amount {transaction.Amount:C}");
                    }
                    break;

                default:
                    break;
                }
            }
        }
Esempio n. 5
0
        public static void PrintBalance(Bank bank, Customer customer)
        {
            var balance = bank.GetBalanceForCustomer(customer.AccountNumber);

            Console.WriteLine("{0} - balance: {1}{2:0.00}", customer.ToString(), balance >= 0 ? "+" : "", balance);
        }