Esempio n. 1
0
        public static int[,] WithdrawalSequence(string value, List <Withdraw> withdrawLists, int[,] notes)
        {
            int totalAmount      = CurrentBalance(notes);
            int withdraw         = 0;
            int _1000CounterTemp = 0;
            int _500CounterTemp  = 0;
            int _100CounterTemp  = 0;

            Console.WriteLine("\n----------------------------------------------\n");
            Console.Write($"Welcome to the RedMind ATM.\nYour current balance is {totalAmount}:-\nEnter [list] to see earlier withdrawals\nOtherwise, please enter the amount you would like to withdraw: ");
            string input = value; //Can be swapped for a Console.ReadLine();

            Console.WriteLine();

            if (input == "list")
            {
                if (withdrawLists.Count == 0)
                {
                    Console.WriteLine("There are no withdrawals so far!");
                }
                else
                {
                    ListOfWithdrawals(withdrawLists);
                }
            }
            else
            {
                bool acceptedInput = true;
                while (acceptedInput)
                {
                    try
                    {
                        withdraw = int.Parse(input);
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("Please only use digits for the amount you would like to withdraw!");
                        break;
                    }

                    var listEntry = new Withdraw();

                    if (withdraw % 100 != 0)
                    {
                        Console.WriteLine("Please select an amount that is divisible by 100.");
                        AddingListItem(withdrawLists, withdraw, listEntry, 2);
                    }
                    else if (withdraw > totalAmount)
                    {
                        Console.WriteLine("Insufficient funds. Please select a lower amount.");
                        AddingListItem(withdrawLists, withdraw, listEntry, 2);
                    }
                    else
                    {
                        int earmarked        = 0;
                        int originWithdrawal = withdraw;

                        while (withdraw >= 1000 && notes[0, 1] > 0)
                        {
                            earmarked += 1000;
                            withdraw   = AfterWithdrawalAmount(withdraw, 1000);
                            _1000CounterTemp++;
                            notes[0, 1]--;
                        }
                        while (withdraw >= 500 && notes[1, 1] > 0)
                        {
                            earmarked += 500;
                            withdraw   = AfterWithdrawalAmount(withdraw, 500);
                            _500CounterTemp++;
                            notes[1, 1]--;
                        }
                        while (withdraw >= 100 && notes[2, 1] > 0)
                        {
                            earmarked += 100;
                            withdraw   = AfterWithdrawalAmount(withdraw, 100);
                            _100CounterTemp++;
                            notes[2, 1]--;
                        }
                        if (originWithdrawal != earmarked)
                        {
                            Console.WriteLine("The ATM can't process your withdrawal request due to lack of bills.");
                            notes[0, 1] += _1000CounterTemp;
                            notes[1, 1] += _500CounterTemp;
                            notes[2, 1] += _100CounterTemp;

                            AddingListItem(withdrawLists, originWithdrawal, listEntry, 2);
                        }
                        else
                        {
                            totalAmount -= originWithdrawal;
                            Console.WriteLine($"Please collect your money: {earmarked}:-\n\t{_1000CounterTemp} X 1000\n\t{_500CounterTemp} X 500\n\t{_100CounterTemp} X 100");

                            AddingListItem(withdrawLists, originWithdrawal, listEntry, 1);
                        }
                    }
                    acceptedInput = false;
                }
            }
            return(notes);
        }
Esempio n. 2
0
 public static void AddingListItem(List <Withdraw> withdrawLists, int withdraw, Withdraw listEntry, int value)
 {
     listEntry.Amount = withdraw;
     listEntry.Result = ListEntries(value);
     withdrawLists.Add(listEntry);
 }