Example #1
0
        public bool SetInterestRate(decimal pSetInterest, AccountSelect pSelectSetIrate)
        {
            switch (pSelectSetIrate)
            {
            ///in the case where pSelectSetIrate == AccountSelect.Account
            case AccountSelect.Account:
                ///if Account.SetInterest given pSetInterest
                ///returns true then this method also returns true
                ///not to mention we have already set the interest at this point
                if (Account.SetInterest(pSetInterest))
                {
                    return(true);
                }
                else
                {
                    ///otherwise we return false
                    return(false);
                }

            case AccountSelect.StudentAccount:
                if (StudentAccount.SetInterest(pSetInterest))
                {
                    return(true);
                }
                else
                {
                    return(false);
                }

            ///if pSelectSetIrate != to Account or StudentAccount then it cannot accept Interest alterations so return false
            default: return(false);
            }
        }
Example #2
0
        public int GetOverdraftLimit(AccountSelect pSelectGetOLimit)
        {
            switch (pSelectGetOLimit)
            {
            case AccountSelect.Account: return(Account.GetOverdraftLimit());

            case AccountSelect.StudentAccount: return(StudentAccount.GetOverdraftLimit());

            default: return(0);
            }
        }
Example #3
0
        public decimal GetInterestRate(AccountSelect pSelectAccount)
        {
            switch (pSelectAccount)
            {
            case AccountSelect.Account:
                return(Account.GetInterest());

            case AccountSelect.StudentAccount:
                return(StudentAccount.GetInterest());

            default: return(0);
            }
        }
Example #4
0
        public IAccount AddAccount(AccountSelect pSelectAdd, string pName, string pAddress, decimal pBalance, decimal pOverdraft)
        {
            ///Look through the array of references looking for
            ///an appropriate place to store a reference to the new account
            for (uint i = 0; i < m_Accounts.Length; ++i)
            {
                if (m_Accounts[i] == null) //if there is an empty space to store an Account reference
                {
                    ///this switch statement works on the enum type that was passed into this method
                    ///it finds out what type of account you wish to create and makes an instance of it
                    ///which can be pointed to/accessed by the IAccount array l_index, m_Accounts[i]
                    switch (pSelectAdd)
                    {
                    ///in the case the variable pSelectAdd
                    ///holds the enum type AccountSelect.Account
                    case AccountSelect.Account:
                        ///make a new Account class instance by calling its constructor
                        ///with the bracketed parameters and reference to it
                        ///from the IAccount array l_index m_Accounts[i]
                        m_Accounts[i] = new Account(dt.Year.ToString() + "A" + sm_NextAccountNumber.ToString("X"), pName, pAddress, pBalance, pOverdraft);
                        break;

                    case AccountSelect.BabyAccount:
                        ///ditto but making a new BabyAccount class instance
                        ///the constructor has no overdraft!
                        m_Accounts[i] = new BabyAccount(dt.Year.ToString() + "A" + sm_NextAccountNumber.ToString("X"), pName, pAddress, pBalance);
                        break;

                    case AccountSelect.StudentAccount:
                        ///currentyear, "A", HexAccountNo, name, address, balance, overdraft
                        m_Accounts[i] = new StudentAccount(dt.Year.ToString() + "A" + sm_NextAccountNumber.ToString("X"), pName, pAddress, pBalance, pOverdraft);
                        break;

                    default: continue;
                    }

                    // increment the next account number
                    sm_NextAccountNumber++;

                    // and return the reference to the new account
                    return(m_Accounts[i]);
                }
            }
            ///if you can't find a place to store the new account
            ///(i.e. the bank is full) then return null.
            return(null);
        }
Example #5
0
        public Bank(string pFileName)
        {
            ///Reference l_reader can point to instances of TextReader
            ///we point it to null because in the finally block we wish
            ///to close a Stream its pointing to only if its pointing to anything
            StreamReader l_reader = null;

            try
            {
                ///point l_reader reference to new StreamReader instance given the parameter pFileName
                ///supplied by the constructor call, as the filename to look for
                l_reader = new StreamReader(pFileName);
                ///ask l_reader reference to find .ReadLine() method in its instance StreamReader
                ///which reads the first line of the txt file and assign its string value to m_Name
                m_Name = l_reader.ReadLine();
                ///create an int to hold number of accounts
                ///its value will be the value of int.Parse(second line of the txt file)
                int l_numberOfAccounts = int.Parse(l_reader.ReadLine());

                //create array of IAccount interfaces the size of the pNumberOfAccounts parameter that was passed into this constructor
                m_Accounts = new IAccount[l_numberOfAccounts];
                ///reads the next line of the txt file and this value
                ///is the next account number to be assigned
                sm_NextAccountNumber = uint.Parse(l_reader.ReadLine());


                ///counter increments when StreamReader.ReadLine() == to the const ACCOUNT_KEY
                ///used to move to next element of m_Accounts[l_index] array
                ///when an account is about to be stored in array
                int l_index = 0;
                ///while the StreamReader.ReadLine() value is == to ACCOUNT_KEY const
                ///ie. the line read from the StreamReader is equal to ACCOUNT_KEY
                while (l_reader.ReadLine() == ACCOUNT_KEY)
                {
                    ///because of the way we had to override the AbstractAccount
                    ///saving method the abstract account saves the balance & overdraft
                    ///immediatly after ACCOUNT_KEY which is why i have to use these temp variables
                    decimal l_tempBalance   = decimal.Parse(l_reader.ReadLine());
                    decimal l_tempOverdraft = decimal.Parse(l_reader.ReadLine());
                    //this is the class name of the type of Account
                    string l_tempTypeofAccount = l_reader.ReadLine();

                    switch (l_tempTypeofAccount)
                    {
                    ///in the case when the string (l_tempTypeofAccount) contains "Account"
                    case "Account": m_Accounts[l_index] = new Account(l_reader.ReadLine(), l_reader.ReadLine(), l_reader.ReadLine(), l_tempBalance, l_tempOverdraft);
                        break;

                    ///The reference to the array of IAccounts is pointed to the subscript of the int value contained in [l_index]
                    ///create new StudentAccount instance calling its constructor & Assign the constructed object to the array
                    case "StudentAccount": m_Accounts[l_index] = new StudentAccount(l_reader.ReadLine(), l_reader.ReadLine(), l_reader.ReadLine(), l_tempBalance, l_tempOverdraft);
                        break;

                    case "BabyAccount": m_Accounts[l_index] = new BabyAccount(l_reader.ReadLine(), l_reader.ReadLine(), l_reader.ReadLine(), l_tempBalance);     //no overdraft for BabyAccount (but we read the default value of zero before)
                        break;

                    default: throw new Exception();
                    }

                    l_index++;//increment l_index because we found a line with value == ACCOUNT_KEY
                }
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
                if (l_reader != null) //if l_reader reference is pointing anywhere
                {
                    l_reader.Close(); //close the stream its pointed to
                }
            }
        }
Example #6
0
        public byte SetOverdraftLimit(int pSetLimit, AccountSelect pSelectSetOLimit)
        {
            ///set to the lowest possible overdraft limit to begin with
            decimal l_HighestOverdraft = 0;

            ///obviously pSetLimit (the amount we want the overdraft limit to be)
            ///must be a positive value
            if (pSetLimit >= 0)
            {
                ///what type of account do we want the overdraft limit to be modified on?
                switch (pSelectSetOLimit)
                {
                ///case where the user selected 'Account'
                case AccountSelect.Account:
                    ///search every reference in IAccount array m_Accounts
                    foreach (IAccount a in m_Accounts)
                    {
                        ///if reference pointing somewhere ie.(not null)
                        ///AND the reference is pointing to an 'Account'
                        if ((a != null) && (a.GetType().Name == "Account"))
                        {
                            ///if the overdraft of currently accessed account is
                            ///greater than previous value in l_HighestOvedraft
                            if (a.GetOverdraft() > l_HighestOverdraft)
                            {
                                ///then the new total becomes this overdraft
                                l_HighestOverdraft = a.GetOverdraft();
                            }
                        }
                    }
                    ///if the number we want to modify the overdraft limit to
                    ///is greater than the highest existing overdraft
                    ///held by any customer of this type of 'Account'
                    if (pSetLimit >= l_HighestOverdraft)
                    {
                        ///then set the overdraft limit to what we asked
                        Account.SetOverdraftLimit(pSetLimit);
                        return(0);    ///return 0 == return true
                    }
                    else
                    {
                        return(2);    ///error: overdraft limit we wanted was less than one of the customers existing overdrafts of this account type
                    }

                ///case where the user selected 'StudentAccount'
                ///ditto as above
                case AccountSelect.StudentAccount:
                    foreach (IAccount a in m_Accounts)
                    {
                        if ((a != null) && (a.GetType().Name == "StudentAccount"))
                        {
                            if (a.GetOverdraft() > l_HighestOverdraft)
                            {
                                l_HighestOverdraft = a.GetOverdraft();
                            }
                        }
                    }
                    if (pSetLimit >= l_HighestOverdraft)
                    {
                        StudentAccount.SetOverdraftLimit(pSetLimit);
                        return(0);    ///return 0 == return true
                    }
                    else
                    {
                        return(2);    ///error: overdraft limit we wanted was less than one of the customers existing overdrafts of this account type
                    }

                default: return(3);    ///the account type you want to alter overdraft limit to does not support changes to the overdraft limit
                }
            }
            else
            {
                return(1); ///error: user tried to set overdraft limit to a negative
            }
        }