Пример #1
0
        static void BusinessAction(BusinessAccount acc, string actionType)
        {
            switch (actionType.ToLower())
            {
            case "deposit":
                Console.WriteLine("enter amount");
                double deposit = Convert.ToInt32(Console.ReadLine());
                acc.Deposit(deposit);
                break;

            case "withdraw":
                Console.WriteLine("enter amount");
                double withdraw = Convert.ToInt32(Console.ReadLine());
                acc.Withdraw(withdraw);
                break;

            case "transfer":
                Console.WriteLine("enter 2nd customer id ");
                int custid = Convert.ToInt32(Console.ReadLine());
                Console.WriteLine("enter 2nd account id");
                int    accId    = Convert.ToInt32(Console.ReadLine());
                var    acc2     = CustomerBL.GetAccount(custid, accId);
                double transfer = Convert.ToInt32(Console.ReadLine());
                acc.Transfer(acc, acc2, transfer);
                break;

            default:
                break;
            }
        }
        public void Deposit(Account account, MyClientDbContext _context, double amount)
        {
            double previous = account.AccountBalance;

            if (account.AccountType == "Checking")
            {
                CheckingAccount checking = new CheckingAccount();
                checking.Deposit(account, amount);
            }
            else if (account.AccountType == "Business")
            {
                BusinessAccount business = new BusinessAccount();
                business.Deposit(account, amount);
            }
            _context.Accounts.Update(account);

            _context.SaveChanges();
            createTransaction(account, previous, account.AccountBalance, amount, "Deposit", _context);
        }
Пример #3
0
        private static void Main(string[] args)
        {
            Account a = new BusinessAccount(1074, "Monica", 1000, 300);
            Account b = new SavingsAccount(1388, "Giovanna", 1500, 1.5);

            if (a is BusinessAccount)
            {
                a.Deposit(100);
            }

            Console.WriteLine(a.Balance);

            if (b is SavingsAccount)
            {
                ((SavingsAccount)b).UpdateBalance();
            }

            Console.WriteLine(b.Balance);

            BusinessAccount c = new BusinessAccount();

            if (a is BusinessAccount)
            {
                c = (BusinessAccount)a;
            }

            Console.WriteLine(c.LoanLimit);

            c.GetLoan(100);

            Console.WriteLine(c.Balance);
            Console.WriteLine(c.LoanLimit);

            a.Withdraw(50);
            b.Withdraw(50);
            c.Withdraw(50);

            Console.WriteLine("$" + a.Balance);
            Console.WriteLine("$" + b.Balance);
            Console.WriteLine("$" + c.Balance);
        }
Пример #4
0
 public void WhenDepositIs100AndBalanceIs0AccountBalanceIs100()
 {
     _bankAccount.Balance = 0;
     _bankAccount.Deposit(100);
     Assert.AreEqual(100, _bankAccount.Balance);
 }
Пример #5
0
        double AnnualInterest; //fixed interest for all checking accounts
        static void Main(string[] args)
        {
            string end;


            Console.WriteLine("\nWelcome to BCMA Banking App!\n-----------------------" +
                              "---------------------------------------------------------\nBCMA allows you to manage your bank account easily and efficiently straight" +
                              " from your console.\n ");
            do
            {
                Console.WriteLine("\nWhich action would you like to perform?\n (1)  Register\n (2)  Open Account\n (3)  Close Account\n" +
                                  " (4)  Deposit\n (5)  Withdraw\n (6)  Transfer\n (7)  Display list of accounts\n (8)  Display list of transactions\n " +
                                  "(9)  Pay loan installment\n");
                //multiple choice kind of thing
                var action = Console.ReadLine();
                Console.WriteLine("--------------------------------");
                if (action == "1") //register
                {
                    Console.WriteLine("You have selected the register option\nPlease fill in your information below:\n");

                    Console.WriteLine("First name: ");
                    var fname = Console.ReadLine();


                    Console.WriteLine("Last name: ");
                    var lname = Console.ReadLine();
                    var name  = fname + " " + lname;

                    //Console.WriteLine("\n");

                    Console.WriteLine("\nUserID: ");
                    Console.ReadLine();

                    Console.WriteLine("Passcode: ");
                    Console.ReadLine();

                    Console.WriteLine("\nWelcome " + name + "!\nThank you for registering your account with BCMA bank.\n-------------Return to menu (q)" +
                                      "------------");
                    int      Id       = 100;
                    Customer customer = new Customer()
                    {
                        Firstname = fname,
                        Lastname  = lname,
                        Id        = Id
                    };
                    Random  random  = new Random();
                    Account account = new Account()
                    {
                        Id            = Id++,
                        accountNumber = random.Next(0, 10000)
                    };
                    customerList.Add(customer);
                    accountList.Add(account);
                    Id++;
                }
                else if (action == "2") //open
                {
                    //TODO: validate ID two customers cannot have the same ID
                    Console.WriteLine("\nWhat type of account would you like to open?\n (1)  Checking account\n" +
                                      " (2)  Business account\n (3)  Term Deposit\n (4)  Loan\n ");

                    var account = Console.ReadLine();
                    switch (account)
                    {
                    case "1":
                        Console.WriteLine("Please type in your Customer Id");
                        Random          random = new Random();
                        CheckingAccount ca     = new CheckingAccount()
                        {
                            Id            = Int32.Parse(Console.ReadLine()),
                            accountNumber = random.Next(0, 10000),
                            accountType   = "Checking",
                            Balance       = random.Next(0, 10000),
                        };

                        Console.Write("\nYour checking account has just been opened\nId:" + ca.Id + "\nAccount Number: " +
                                      ca.accountNumber + " \nAccount Type: " + ca.accountType + "\nStart Balance:  $" + ca.Balance);
                        double AnnualInterest = 0.5;     //fixed interest for all checking accounts
                        Console.WriteLine("\nAnnual Percent Yield(APY): " + AnnualInterest + "%");

                        accountList.Add(ca);

                        Console.WriteLine(" \n------------- Return to menu (q) ------------");
                        break;

                    case "2":
                        Console.WriteLine("Please type in your Customer Id");
                        Random          random1 = new Random();
                        BusinessAccount ba      = new BusinessAccount()
                        {
                            Id            = Int32.Parse(Console.ReadLine()),
                            accountNumber = random1.Next(0, 10000),
                            accountType   = "Business",
                            Balance       = random1.Next(0, 10000),
                        };
                        Console.Write("Your business account has just been opened\nId:" + ba.Id + "\nAccount Number: " + ba.accountNumber
                                      + "\nAccount Type: " + ba.accountType + "\nStart Balance: $" + ba.Balance);
                        double AnnualInterest2 = 0.6;
                        Console.WriteLine("\nAnnual Percent Yield(APY): " + AnnualInterest2 + "%");
                        accountList.Add(ba);
                        Console.WriteLine(" \n------------- Return to menu (q) ------------");
                        break;

                    case "3":    //term dep
                        Console.WriteLine("Please type in your Customer Id");
                        Random      random2 = new Random();
                        TermDeposit td      = new TermDeposit()
                        {
                            Id            = Int32.Parse(Console.ReadLine()),
                            accountNumber = random2.Next(0, 10000),
                            accountType   = "Term Deposit",
                            Balance       = random2.Next(0, 10000),
                        };
                        Console.Write("Your term deposit account has just been opened\n Id: " + td.Id + "\nAccount Number: " +
                                      td.accountNumber + " \nAccount Type: " + td.accountType + "\nStart Balance: $");
                        double AnnualInterest3 = 0.6;
                        Console.WriteLine("\nAnnual Percent Yield(APY): " + AnnualInterest3 + "%");
                        accountList.Add(td);
                        Console.WriteLine(" \n------------- Return to menu (q) ------------");
                        break;

                    case "4":    //loan
                        Console.WriteLine("Please type in your Customer Id");
                        Random random4 = new Random();
                        Loan   l       = new Loan()
                        {
                            Id            = Int32.Parse(Console.ReadLine()),
                            accountNumber = random4.Next(0, 10000),
                            accountType   = "Loan",
                        };
                        l.Balance = random4.Next(0, 10000);
                        Console.Write("Your loan has just been opened\n Id:" + l.Id + "\nAccount Number: " +
                                      l.accountNumber + " \nAccount Type: " + l.accountType + "\nStart Balance: $" + l.Balance);
                        accountList.Add(l);
                        Console.WriteLine(" \n------------- Return to menu (q) ------------");
                        break;

                    default:
                        Console.WriteLine("WARNING: No further action can be performed.\n Press q to " +
                                          "return back to the main menu...");
                        break;
                    }
                }
                else if (action == "3") //close
                                        //updates list With new values
                {
                    Console.WriteLine("Which account would you like to close?\n (1)Checking account\n " +
                                      "(2)Business account\n");

                    var account = Console.ReadLine();
                    switch (account)
                    {
                    case "1":     //checking account
                                  //essentailly need to delete from the list and update

                        Console.WriteLine("What is your ID number?");
                        var number = Convert.ToInt32(Console.ReadLine());
                        Console.WriteLine("Searching for Customer ID:\n " + number);
                        CheckingAccount ca = new CheckingAccount()
                        {
                            Id            = number,
                            accountNumber = 0,              //0 means closed
                            accountType   = "Checking"
                        };
                        Console.Write("Your checking account has been closed:\n Id:" + ca.Id + "\nAccount Number: "
                                      + ca.accountNumber + "\nAccount Type: " + ca.accountType);

                        Console.WriteLine(" \n------------- Return to menu (q) ------------");
                        break;

                    case "2":    //business account
                        Console.WriteLine("What is your ID number?");
                        var number1 = Convert.ToInt32(Console.ReadLine());
                        Console.WriteLine("Searching for Customer ID: " + number1);
                        BusinessAccount ba = new BusinessAccount()
                        {
                            Id            = number1,
                            accountNumber = 0,              //0 means closed
                            accountType   = "Business"
                        };

                        Console.Write("Your business account has been closed:\n Id:" + ba.Id + "\nAccount Number: "
                                      + ba.accountNumber + "\nAccount Type: " + ba.accountType);
                        Console.WriteLine(" \n------------- Return to menu(q) ------------");
                        break;

                    default:
                        Console.WriteLine("WARNING: No further action can be performed.\n Press q to " +
                                          "return back to the main menu...");
                        break;
                    }
                }
                else if (action == "4") //deposit
                {                       //TODO: Based on account number when you paste the number you should deposit into that specific account
                    //need a transaction list for each customer
                    Console.WriteLine("Which account would you like to deposit money into?\n (1)Checking account\n (2)Business account\n (3) Term Despoit\n ");
                    var account = Console.ReadLine();
                    switch (account)
                    {
                    case "1":
                        CheckingAccount ca = new CheckingAccount();
                        Console.WriteLine("Please enter your account number:\n");
                        ca.accountNumber = Int32.Parse(Console.ReadLine());
                        //Random random = new Random();
                        //ca.accountNumber = random.Next(0, 10000);
                        //Console.WriteLine("Your account number: " + ca.accountNumber);
                        ca.accountType = "Checking";
                        Console.WriteLine("How much would you like to deposit?");
                        ca.Balance = ca.Deposit(Convert.ToDouble(Console.ReadLine()));
                        // double amount = ca.Balance + l.Balance;
                        Console.WriteLine($"Id: {ca.Id}\nAccount Number: {ca.accountNumber}\n" +
                                          $"Account type: {ca.accountType}\nBalance: ${ca.Balance}");

                        // transactionList.Add(ca.Balance);

                        //foreach (Account item in accountList)
                        //{
                        //    if (ca.accountNumber == item.accountNumber)
                        //    {
                        //        Console.WriteLine("cno");
                        //        item.Balance += ca.Balance;
                        //    }
                        //}
                        transactionList.Add(ca.Balance);
                        Console.WriteLine(" \n------------- Return to menu (q) ------------");
                        break;

                    case "2":
                        BusinessAccount ba = new BusinessAccount();
                        Console.WriteLine("Please enter your Customer ID:\n");
                        ba.Id = Int32.Parse(Console.ReadLine());
                        Random random1 = new Random();
                        ba.accountNumber = random1.Next(0, 10000);
                        Console.WriteLine("Your account number: " + ba.accountNumber);
                        ba.accountType = "Checking";
                        Console.WriteLine("How much would you like to deposit?");
                        ba.Balance = ba.Deposit(Convert.ToDouble(Console.ReadLine()));
                        Console.WriteLine($"Id: {ba.Id}\nAccount Number: {ba.accountNumber}\n" +
                                          $"Account type: {ba.accountType}\nBalance: ${ba.Balance}");
                        transactionList.Add(ba.Balance);
                        Console.WriteLine(" \n------------- Return to menu (q) ------------");
                        break;

                    case "3":
                        TermDeposit td = new TermDeposit();
                        Console.WriteLine("Please enter your Customer ID:\n");
                        td.Id = Int32.Parse(Console.ReadLine());
                        Random random2 = new Random();
                        td.accountNumber = random2.Next(0, 10000);
                        Console.WriteLine("Your account number: " + td.accountNumber);
                        td.accountType = "Checking";
                        Console.WriteLine("How much would you like to deposit?");
                        td.Balance = td.Deposit(Convert.ToDouble(Console.ReadLine()));
                        Console.WriteLine($"Id: {td.Id}\nAccount Number: {td.accountNumber}\n" +
                                          $"Account type: {td.accountType}\nBalance: ${td.Balance}");
                        transactionList.Add(td.Balance);
                        Console.WriteLine(" \n------------- Return to menu (q) ------------");
                        break;

                    default:
                        Console.WriteLine("WARNING: No further action can be performed.\n Press q to " +
                                          "return back to the main menu...");

                        break;
                    }
                }
                else if (action == "5") //withdraw
                {
                    Console.WriteLine("Which account would you like to withdraw money from? (1)Checking account\n " +
                                      "(2)Business account\n (3) Term Deposit\n ");
                    var account = Console.ReadLine();
                    switch (account)
                    {
                    case "1":    //checking

                        CheckingAccount ca = new CheckingAccount();
                        Console.WriteLine("Please enter your Customer ID:\n");
                        ca.Id = Int32.Parse(Console.ReadLine());
                        Random random = new Random();
                        ca.accountNumber = random.Next(0, 10000);
                        Console.WriteLine("Your account number: " + ca.accountNumber);
                        ca.accountType = "Checking";
                        Console.WriteLine("How much would you like to withdraw?");
                        ca.Balance = ca.Withdraw(Convert.ToDouble(Console.ReadLine()));
                        Console.WriteLine(ca.Balance);
                        Console.WriteLine($"Id: {ca.Id}\nAccount Number: {ca.accountNumber}\n" +
                                          $"Account type: {ca.accountType}\nBalance: ${ca.Balance}");
                        transactionList.Add(ca.Balance);
                        Console.WriteLine(" \n------------- Return to menu (q) ------------");
                        break;

                    case "2":     //business
                        BusinessAccount ba = new BusinessAccount();

                        Console.WriteLine("Please enter your Customer ID:\n");
                        ba.Id = Int32.Parse(Console.ReadLine());

                        Random random1 = new Random();
                        ba.accountNumber = random1.Next(0, 10000);

                        Console.WriteLine("Your account number: " + ba.accountNumber);
                        ba.accountType = "Business";

                        Console.WriteLine("How much would you like to withdraw?");
                        ba.Balance = ba.Withdraw(Convert.ToDouble(Console.ReadLine()));

                        Console.WriteLine(ba.Balance);
                        Console.WriteLine($"Id: {ba.Id}\nAccount Number: {ba.accountNumber}\n" +
                                          $"Account type: {ba.accountType}\nBalance: ${ba.Balance}");
                        transactionList.Add(ba.Balance);
                        Console.WriteLine(" \n------------- Return to menu (q) ------------");
                        break;

                    case "3":     //term deposit
                        TermDeposit td = new TermDeposit();
                        Console.WriteLine("Please enter your Customer ID:\n");
                        td.Id = Int32.Parse(Console.ReadLine());
                        Random random2 = new Random();
                        td.accountNumber = random2.Next(0, 10000);
                        Console.WriteLine("Your account number: " + td.accountNumber);
                        td.accountType = "Term Deposit";
                        Console.WriteLine("How much would you like to withdraw?");
                        td.Balance = td.Withdraw(Convert.ToDouble(Console.ReadLine()));
                        Console.WriteLine(td.Balance);
                        Console.WriteLine($"Id: {td.Id}\nAccount Number: {td.accountNumber}\n" +
                                          $"Account type: {td.accountType}\nBalance: ${td.Balance}");
                        transactionList.Add(td.Balance);
                        Console.WriteLine(" \n------------- Return to menu (q) ------------");
                        break;

                    default:
                        Console.WriteLine("WARNING: No further action can be performed.\n Press q to " +
                                          "return back to the main menu...");
                        break;
                    }
                }

                else if (action == "6") //transfer
                {
                    Console.WriteLine("Which account would you like to transfer money from? " +
                                      "(1)Checking account\n (2)Business account\n ");

                    var account = Console.ReadLine();
                    switch (account)
                    {
                    case "1":
                        Console.WriteLine("You are now transferring money to your Business account\n");
                        Console.WriteLine("How much would you like to transfer?");
                        var transfer = Console.ReadLine();


                        CheckingAccount ca     = new CheckingAccount();
                        Transfer        t      = new Transfer();
                        double          amount = ca.Withdraw(Int32.Parse(transfer));
                        transactionList.Add(amount);
                        Console.WriteLine("transfer to business complete");
                        Console.WriteLine(" \n------------- Return to menu (q) ------------");
                        break;

                    case "2":
                        Console.WriteLine("You are now transferring money to your Business account\n");
                        Console.WriteLine("How much would you like to transfer?");
                        var transfer1 = Console.ReadLine();

                        Console.WriteLine("How much would you like to transfer?");
                        BusinessAccount ba      = new BusinessAccount();
                        Transfer        t1      = new Transfer();
                        double          amount1 = ba.Withdraw(Int32.Parse(transfer1));
                        transactionList.Add(amount1);
                        Console.WriteLine("transfer to business complete");
                        Console.WriteLine(" \n------------- Return to menu (q) ------------");
                        break;

                    default:
                        Console.WriteLine("WARNING: No further action can be performed.\n Press q to return to menu...");
                        break;
                    }
                }
                else if (action == "7") //display accounts
                {
                    foreach (Account item in accountList)
                    {
                        Console.WriteLine($"Id: {item.Id}\nAccount Number: {item.accountNumber}\n" +
                                          $"Account type: {item.accountType}");
                        Console.WriteLine("-----------------------------");
                    }
                }
                else if (action == "8")//display transactions
                {
                    //TODO: need to figure out how to print the acct number and transaction

                    foreach (double item in transactionList)
                    {
                        Console.WriteLine("What is your account number?");
                        var trans = Console.ReadLine();
                        Console.WriteLine($"\nAccount Number: {trans}");
                        Console.WriteLine($"Transaction history: $" + item);
                        Console.WriteLine("-----------------------------");
                    }
                }
                else if (action == "9") //pay loan
                {
                    Console.WriteLine("From which account would you like to pay your loan? (1)Checking (2) Business");
                    var pay = Console.ReadLine();
                    if (pay == "1") //checking
                    {
                        Console.WriteLine("What is your Customer Id?");
                        var id = Int32.Parse(Console.ReadLine());

                        Console.WriteLine("Customer Id:" + id);

                        CheckingAccount ca = new CheckingAccount();

                        Loan loan = new Loan();
                        Console.WriteLine("How much money would you like to pay? ");
                        loan.PayLoan(Convert.ToDouble(Console.ReadLine()));

                        double deduction = ca.Withdraw(loan.PayLoan(Convert.ToDouble(Console.ReadLine())));
                        transactionList.Add(deduction);
                        Console.WriteLine(" \n------------- Return to menu (q) ------------");
                    }
                    else if (pay == "2") //business
                    {
                        Console.WriteLine("What is your Customer Id?");
                        var id = Int32.Parse(Console.ReadLine());

                        Console.WriteLine("Customer Id:" + id);

                        BusinessAccount ba = new BusinessAccount();

                        Loan loan = new Loan();
                        Console.WriteLine("How much money would you like to pay? ");
                        loan.PayLoan(Convert.ToDouble(Console.ReadLine()));

                        double deduction = ba.Withdraw(loan.PayLoan(Convert.ToDouble(Console.ReadLine())));
                        transactionList.Add(deduction);
                        Console.WriteLine(" \n------------- Return to menu (q) ------------");
                    }
                }
                else
                {
                    Console.WriteLine("WARNING: No further action can be performed.\n Return to menu q...");
                }

                end = Console.ReadLine();
            } while (end == "q");
        }