Example #1
0
        /// <summary>
        /// withdraw does the validation of account detailsand then deposits into the account
        /// </summary>
        /// <param name="acc">this param takestheaccount number</param>
        /// <param name="pin">this param takes the pin of the acc</param>
        /// <param name="amount">this param takes the amount to be withdrawn</param>
        /// <returns>returns new acc balance and index of customer</returns>
        public double[] withdraw(String acc, string pin, double amount)
        {
            int index = 0;

            double[] tempacc = new double[2];

            index = checacc(acc, pin);
            if (cus[index].Acctyp == "Savings")
            {
                Savings s = new Savings();
                cus[index].AccountBalance = s.withdraw(amount, cus[index].AccountBalance);

                tempacc[0] = cus[index].AccountBalance;
            }
            else if (cus[index].Acctyp == "Current")
            {
                Current c = new Current();
                cus[index].AccountBalance = c.withdraw(amount, cus[index].AccountBalance);
                tempacc[0] = cus[index].AccountBalance;
            }
            else
            {
                Console.WriteLine("Account Not Found");
            }

            tempacc[1] = index;
            //Done!
            return(tempacc);
        }
Example #2
0
        /// <summary>
        /// transfer does transfer of money from acc to acc2
        /// </summary>
        /// <param name="acc">this param takes the account number of customer</param>
        /// <param name="pin">this param takes the pin of the acc</param>
        /// <param name="amount">this param takes the amount to be transferred</param>
        /// <param name="acc2">this param takes the account number of reciepient</param>
        /// <returns>returns new acc balance of the two customers in an array and the index of the customer</returns>
        public double[] transfer(String acc, string pin, double amount, String acc2)
        {
            int cnt = cus.Count();

            double[] result = new double[3];
            double   tempacc;
            int      index  = 0;
            int      index2 = 0;
            bool     z      = false;

            index = checacc(acc, pin);

            //validate second account
            for (int j = 0; j < cnt; j++)
            {
                if (acc2 == cus[j].AccountNumber)
                {
                    index2 = j;
                    z      = true;
                    break;
                }
            }

            //else print not found
            if (z == false)
            {
                Console.WriteLine("AI>> Reciepient account not found");
                two();
            }

            if (cus[index].Acctyp == "Savings")
            {
                Savings s = new Savings();
                cus[index2].AccountBalance = s.deposit(amount, cus[index2].AccountBalance);
                cus[index].AccountBalance  = s.withdraw(amount, cus[index].AccountBalance);
                tempacc = cus[index].AccountBalance;
            }
            else if (cus[index].Acctyp == "Current")
            {
                Current c = new Current();
                cus[index2].AccountBalance = c.deposit(amount, cus[index2].AccountBalance);
                cus[index].AccountBalance  = c.withdraw(amount, cus[index].AccountBalance);
                tempacc = cus[index].AccountBalance;
            }
            else
            {
                Console.WriteLine("Account Not Found");
                two();
            }

            result[0] = cus[index].AccountBalance;
            result[1] = cus[index2].AccountBalance;
            result[2] = index;
            Console.WriteLine("Transfer Successful");


            return(result);
        }