コード例 #1
0
ファイル: Bank.cs プロジェクト: vivekduttamishra/202002-hw-cs
        public int OpenAccount(string type, string customerName, string password, int amount)
        {
            //TODO: step 1. create BankAccount object
            //int accountNumber = ++lastId;  //generate new account number

            BankAccount account = null;

            switch (type)
            {
            case "SavingsAccount":
                account = new SavingsAccount(0, customerName, password, amount);
                break;

            case "CurrentAccount":
                account = new CurrentAccount(0, customerName, password, amount);
                break;

            case "OverdraftAccount":
                account = new OverdraftAccount(0, customerName, password, amount);
                break;
            }

            //TODO: step 2.  store the account object in Bank Object
            return(AccountRepository.AddAccount(account));

            //TODO: step 3.  return the account number
            //return account.AccountNumber;
        }
コード例 #2
0
ファイル: Bank.cs プロジェクト: vivekduttamishra/202002-hw-cs
        public int OpenAccount(string customerName, string password, int amount, string accountType = "SavingsAccount")
        {
            //TODO: step 1. create BankAccount object
            int         accountNumber = ++lastId; //generate new account number
            BankAccount account       = null;

            switch (accountType)
            {
            case "SavingsAccount":
                account = new SavingsAccount(accountNumber, customerName, password, amount); break;

            case "CurrentAccount":
                account = new CurrentAccount(accountNumber, customerName, password, amount); break;

            case "OverdraftAccount":
                account = new OverdraftAccount(accountNumber, customerName, password, amount); break;
            }


            //TODO: step 2.  store the account object in Bank Object
            AddAccount(account);

            //TODO: step 3.  return the account number
            return(accountNumber);
        }
コード例 #3
0
        public AccountStore Load(string path)
        {
            StreamReader reader = null;
            var          store  = new AccountStore();

            try
            {
                reader       = new StreamReader(path);
                store.LastId = int.Parse(reader.ReadLine()); //first line contains last id


                while (true)
                {
                    var str = reader.ReadLine();
                    if (str == null)
                    {
                        break;
                    }

                    var         parts       = str.Split(',');
                    var         id          = int.Parse(parts[0]);
                    var         name        = parts[1];
                    var         pass        = parts[2];
                    var         balance     = double.Parse(parts[3]);
                    var         accountType = parts[4];
                    BankAccount account     = null;
                    switch (accountType)
                    {
                    case "SavingsAccount": account = new SavingsAccount(id, name, pass, 0); break;

                    case "CurrentAccount": account = new CurrentAccount(id, name, pass, 0); break;

                    case "OverdraftAccount": account = new OverdraftAccount(id, name, pass, 0); break;
                    }
                    account.Deposit(balance);
                    store.Accounts[id] = account;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                reader.Close();
            }

            return(store);
        }
コード例 #4
0
        public int OpenAccount(string customerName, string password, int amount, string accountType = "SavingsAccount")
        {
            //TODO: step 1. create BankAccount object

            BankAccount account = null;

            switch (accountType)
            {
            case "SavingsAccount":
                account = new SavingsAccount(0, customerName, password, amount); break;

            case "CurrentAccount":
                account = new CurrentAccount(0, customerName, password, amount); break;

            case "OverdraftAccount":
                account = new OverdraftAccount(0, customerName, password, amount); break;
            }


            //TODO: step 2.  store the account object in Bank Object
            return(AccountRepository.AddAccount(account));
        }