示例#1
0
        internal static void CreateAccount(Bank mybank)
        {
            Console.WriteLine("\nSelect Account type:\n1. Loan Account,  2.Deposit Account");
            Console.Write("Your Reply: ");
            string    option = Console.ReadLine();
            ICustomer newCustomer; decimal startAmt;

            switch (Convert.ToInt32(option))
            {
            case 1:
                Console.Write("Enter Amount: ");
                startAmt = Utility.GetDecimal(Console.ReadLine());
                Console.WriteLine("Enter Loan Duration (greater than 3): ");
                int duration = Convert.ToInt32(Console.ReadLine());
                newCustomer = GenerateNewCustomer(GetCustomerType());
                LoanAccount acct = new LoanAccount(newCustomer, startAmt, duration);
                mybank.AddNewAccount(acct);
                break;

            case 2:
                Console.Write("Enter Amount: ");
                startAmt = Utility.GetDecimal(Console.ReadLine());
                Console.Write("Choose your Deposit Account Type\n Reply with Student,Savings or Current:  ");
                DepositAccountType acctType = Utility.GetDepositAccountType(Console.ReadLine());
                newCustomer = GenerateNewCustomer(GetCustomerType());
                DepositAccount acctDep = new DepositAccount(newCustomer, acctType, startBalance: startAmt);
                mybank.AddNewAccount(acctDep);
                break;

            default:
                throw new ArgumentException("Invalid Account type entered.");
            }
        }
示例#2
0
 internal DepositAccount(ICustomer customer, DepositAccountType type, decimal startBalance = 0)
 {
     if (customer is CompanyCustomer && type == DepositAccountType.Student)
     {
         Exception e = new Exception("Company Account Cannot Open a Student Account");
         throw e;
     }
     else
     {
         if (Utility.IsValidStartBalance(type, startBalance))
         {
             Balance   = startBalance;
             this.type = type;
             SetDateOpened();
             SetAccountNumber();
             this.customer = customer;
         }
         else
         {
             Exception e = new Exception($"Invalid StartBalance: {startBalance} is less than {type} account " +
                                         $"minimum balance of {(int)type}");
             throw e;
         }
     }
 }
示例#3
0
        internal static bool IsValidStartBalance(DepositAccountType accountType, decimal startBalance)
        {
            bool isValid = false;

            switch ((int)accountType)
            {
            case 0:    //students
                if (startBalance < 0)
                {
                    isValid = false;
                }
                else
                {
                    isValid = true;
                }
                break;

            case 1000:    // savings
                if (startBalance < 1000)
                {
                    isValid = false;
                }
                else
                {
                    isValid = true;
                }
                break;

            case 10000:     //current
                if (startBalance < 10000)
                {
                    isValid = false;
                }
                else
                {
                    isValid = true;
                }
                break;
            }
            return(isValid);
        }