コード例 #1
0
        /// <summary>
        /// Creates a new account for a customer and saves the account details to the database.
        /// Requires: The Banks Policy conditions for minimum age to be eligible to open current and savings accounts are set.
        /// Requires: The Banks Policy conditions for minimum amount to be eligible to open current and savings accounts are set.
        /// </summary>
        /// <exception cref="InvalidDataException">Thrown when user enters wrong account type or gender</exception>
        /// <exception cref="InvalidOperationException">Thrown when the customer is not eligible to open any account</exception>
        public virtual void CreateAccount()
        {
            Contract.Requires(BankPolicy <CurrentAccount> .MinimumAge > 0 && BankPolicy <SavingsAccount> .MinimumAge > 0);
            Contract.Requires(BankPolicy <CurrentAccount> .minimumBalance >= 0 || BankPolicy <SavingsAccount> .minimumBalance >= 0);
            Console.WriteLine("----------------------------");
            Console.WriteLine("CREATE ACCOUNT");
            Console.WriteLine("Enter Preferred Account Name");
            string accountName = Console.ReadLine();

            Console.WriteLine("Enter Customer Age");
            age = int.Parse(Console.ReadLine());
            Console.WriteLine("Enter Initial Deposit Amount");
            double accountBalance = double.Parse(Console.ReadLine());

            Console.WriteLine("What Type of Account?");
            Console.WriteLine("Savings(S), Current(C)");
            string accountType = Console.ReadLine();

            switch (accountType.ToUpper())
            {
            case "S":
                accountType = "Savings";
                if (age < BankPolicy <SavingsAccount> .MinimumAge || accountBalance < BankPolicy <SavingsAccount> .minimumBalance)
                {
                    throw new InvalidOperationException("Please check the banks policies for age and minimum balance for savings accounts");
                }
                break;

            case "C":
                accountType = "Current";
                if (age < BankPolicy <CurrentAccount> .MinimumAge || accountBalance < BankPolicy <CurrentAccount> .minimumBalance)
                {
                    throw new InvalidOperationException("Please check the banks policies for age and minimum balance for current accounts");
                }
                break;

            default:
                throw new InvalidDataException("Wrong Account type");
            }

            string accountNumber = AccountNumberGenerator.GenerateUniqueString(10);    //crypto random number generator for account number


            Console.WriteLine("Enter customer name");
            Name = Console.ReadLine();
            Console.WriteLine("Enter Customer Gender");
            Console.WriteLine("Male(M), Female(F)");
            string customerGender = (Console.ReadLine());

            switch (customerGender.ToUpper())
            {
            case "M":
                customerGender = "Male";
                break;

            case "F":
                customerGender = "Female";
                break;

            default:
                throw new InvalidDataException("Wrong Gender!");
            }
            Console.WriteLine("Enter Customer Phone Number");
            phonenumber = Console.ReadLine();

            Console.WriteLine("Enter Customer Email Address");
            email_address = Console.ReadLine();
            Console.WriteLine("Enter Customer House Address");
            house_address = Console.ReadLine();
            Console.WriteLine("");

            // Save the account to the database
            SaveAccount(accountNumber, accountType, accountName, accountBalance, Name, customerGender, phonenumber, age, email_address, house_address);
            Console.WriteLine("Congrats! Your account number is " + accountNumber);
        } //end CreateAccount method
コード例 #2
0
        /// <summary>
        /// Creates a new account for a customer and saves the account details to the database.
        /// Requires: The Banks Policy conditions for minimum age to be eligible to open current and savings accounts are set.
        /// Requires: The Banks Policy conditions for minimum amount to be eligible to open current and savings accounts are set.
        /// </summary>
        /// <exception cref="InvalidDataException">Thrown when user enters wrong account type or gender</exception>
        /// <exception cref="InvalidOperationException">Thrown when the customer is not eligible to open any account</exception>
        /// <exception cref="FormatException">Thrown when user input is of the wrong format</exception>
        public virtual void CreateAccount()
        {
            Contract.Requires(BankPolicy.MinimumAge > 0);
            Contract.Requires(BankPolicy.minimumcurrentBalance > 0 || BankPolicy.minimumsavingsBalance >= 0);
            Console.WriteLine("----------------------------");
            Console.WriteLine("CREATE ACCOUNT");
            Console.WriteLine("Enter customer name");
            Name = Console.ReadLine();
            Console.WriteLine("Enter Customer Gender");
            Console.WriteLine("Male(M), Female(F)");
            string customerGender = (Console.ReadLine());

            switch (customerGender.ToUpper())
            {
            case "M":
                customerGender = "Male";
                break;

            case "F":
                customerGender = "Female";
                break;

            default:
                throw new InvalidDataException("Wrong Gender!");
            }
            Console.WriteLine("Enter Birthday (mm/dd/yyyy)");
            Birthday = DateTime.Parse(Console.ReadLine());

            if (DateTime.Today.Year - Birthday.Year < BankPolicy.MinimumAge)
            {
                throw new InvalidOperationException("Please you are too young to open an account");
            }

            Console.WriteLine("Enter Customer Phone Number");
            phonenumber = Console.ReadLine();

            if (!checkPhoneNumberValidity(phonenumber).Equals(true))
            {
                throw new FormatException("Please check that the phone number format is correct");
            }

            Console.WriteLine("Enter Customer Email Address");
            email_address = Console.ReadLine();

            if (!checkEmailValidity(email_address).Equals(true))
            {
                throw new FormatException("Not an email address, please check input");
            }

            Console.WriteLine("Enter Customer House Address");
            house_address = Console.ReadLine();
            Console.WriteLine("");

            Console.WriteLine("Enter Preferred Account Name");
            string accountName = Console.ReadLine();
            double accountBalance;

            Console.WriteLine("What Type of Account?");
            Console.WriteLine("Savings(S), Current(C)");
            string accountType = Console.ReadLine();

            switch (accountType.ToUpper())
            {
            case "S":
                accountType = "Savings";
                Console.WriteLine("Enter Initial Deposit Amount");
                accountBalance = double.Parse(Console.ReadLine());
                if (accountBalance < BankPolicy.minimumsavingsBalance)
                {
                    throw new InvalidOperationException("Please check the banks policies for minimum balance for savings accounts");
                }
                break;

            case "C":
                accountType = "Current";
                Console.WriteLine("Enter Initial Deposit Amount");
                accountBalance = double.Parse(Console.ReadLine());
                if (accountBalance < BankPolicy.minimumcurrentBalance)
                {
                    throw new InvalidOperationException("Please check the banks policies for minimum balance for savings accounts");
                }
                break;

            default:
                throw new InvalidDataException("Wrong Account type");
            }

            string accountNumber = AccountNumberGenerator.GenerateUniqueString(10);    //crypto random number generator for account number



            // Save the account to the database
            SaveAccount(accountNumber, accountType, accountName, accountBalance, Name, customerGender, phonenumber, Birthday, email_address, house_address);
            Console.WriteLine("Congrats! Your account number is " + accountNumber);
        } //end CreateAccount method