예제 #1
0
        public override TripStateLoop.Status Execute()
        {
            Console.WriteLine(Environment.NewLine + "*** ADD THANK YOU ***");
            Console.WriteLine();
            Console.WriteLine("- COMMAND: [later] to return later or write thank you note (5 chars min)");

            var    getThankYou = true;
            string thankYou    = null;

            while (getThankYou)
            {
                thankYou = (Console.ReadLine() ?? "").Trim();

                //come back later?
                if (ReturnLater(thankYou))
                {
                    return(TripStateLoop.Status.Stop);
                }

                //stop if we can change state
                getThankYou = !IsThankYouValid(thankYou);
            }

            TripContext.Trip.ThankYou = thankYou;
            TripContext.ChangeState(new TripStateComplete(TripContext));
            return(TripStateLoop.Status.Continue);
        }
예제 #2
0
        public override TripStateLoop.Status Execute()
        {
            decimal amount = 0;

            Console.WriteLine(Environment.NewLine + "*** ACCEPT CASH PAYMENT ***");
            Console.WriteLine();
            Console.WriteLine("- COMMAND: [later] to return later or amount");
            Console.WriteLine();

            Console.WriteLine($"The total amount for the trip is: ${TripContext.Trip.totalPrice}");
            Console.WriteLine("- Enter amount or [later] to return later");
            Console.WriteLine();


            // loops to handle user input
            var enterAmount = true;

            while (enterAmount)
            {
                string newAmount = (Console.ReadLine() ?? "").Trim();

                //int payerNumber = Int32.Parse(Console.ReadLine());
                if (Decimal.TryParse(newAmount, out amount))
                {
                    if (amount > TripContext.Trip.totalPrice)
                    {
                        Console.WriteLine("You are overpaying, we don't need your pity, please re-enter amount");
                        continue;
                    }

                    if (amount < TripContext.Trip.totalPrice)
                    {
                        Console.WriteLine("You are underpaying, please, we are struggling, re-enter amount");
                        continue;
                    }
                }
                else if (ReturnLater(newAmount))
                {
                    return(TripStateLoop.Status.Stop);
                }



                else
                {
                    Console.WriteLine("Please enter a valid number");
                }

                break;
            }


            TripContext.Trip.Payment = new PaymentCash(amount);
            Console.WriteLine($"{TripContext.Trip.Payer} paid {TripContext.Trip.totalPrice} by cash");

            //change state when finished
            TripContext.ChangeState(new TripStateAddThankYou(TripContext));
            return(TripStateLoop.Status.Continue);
        }
        public override TripStateLoop.Status Execute()
        {
            for (int x = 0; x < TripContext.Trip.selectedPacks.Count; x++)
            {
                TripContext.Trip.totalPrice += Math.Abs(TripContext.Trip.selectedPacks[x].price);
            }

            Console.WriteLine($"THE TOTAL PRICE OF THE TRIP IS: ${TripContext.Trip.totalPrice}");
            Console.WriteLine();
            Console.WriteLine("COMMAND: ENTER THE NUMBER OF THE TRAVELLER WHO WILL BE PAYING OR [later] TO RETURN LATER:");
            Console.WriteLine();



            for (int x = 0; x < TripContext.Trip.selectedTravellers.Count; x++)
            {
                Console.WriteLine($"{x + 1}: " + TripContext.Trip.selectedTravellers[x].ToString());
            }

            var selectPayer = true;

            while (selectPayer)
            {
                string newPayer = (Console.ReadLine() ?? "").Trim();

                //int payerNumber = Int32.Parse(Console.ReadLine());
                if (Int32.TryParse(newPayer, out int payerNumber) && (payerNumber > 0 &&
                                                                      payerNumber < TripContext.Trip.selectedTravellers.Count + 1))
                {
                    Console.WriteLine($"Payer = { TripContext.Trip.selectedTravellers[payerNumber - 1].ToString() }");
                    TripContext.Trip.Payer = TripContext.Trip.selectedTravellers[payerNumber - 1];
                    break;
                }
                else if (ReturnLater(newPayer))
                {
                    return(TripStateLoop.Status.Stop);
                }

                else
                {
                    Console.WriteLine("Please enter a valid number");
                }
            }

            Console.WriteLine(Environment.NewLine + "*** CHOOSE PAYMENT TYPE ***");
            Console.WriteLine();
            Console.WriteLine("- COMMAND: [later] to return later, [cash] or [check] or [card]");

            while (true)
            {
                var paymentType = (Console.ReadLine() ?? "").Trim();
                if (ReturnLater(paymentType))
                {
                    return(TripStateLoop.Status.Stop);                          //exit loop and method
                }
                //empty entry does nothing
                if (string.IsNullOrWhiteSpace(paymentType))
                {
                    continue;
                }

                if (paymentType == "cash")
                {
                    TripContext.ChangeState(new TripStatePayCash(TripContext));
                    return(TripStateLoop.Status.Continue);
                }

                if (paymentType == "check")
                {
                    TripContext.ChangeState(new TripStatePayCheck(TripContext));
                    return(TripStateLoop.Status.Continue);
                }

                if (paymentType == "card")
                {
                    TripContext.ChangeState(new TripStatePayCard(TripContext));
                    return(TripStateLoop.Status.Continue);
                }

                Console.WriteLine("- ERROR: [later], [cash], [check], or [card]");
            }
        }
예제 #4
0
        public override TripStateLoop.Status Execute()
        {
            Console.WriteLine(Environment.NewLine + "*** ADD PACKAGES ***");
            Console.WriteLine();



            for (int x = 0; x < premadePacks.Count; x++)
            {
                Console.WriteLine($"{x + 1}: " + premadePacks[x].ToString());
                Console.WriteLine();
            }



            ShowCurrentDestinations();
            Console.WriteLine(
                "- COMMAND: [later] to return later, [done] to finish destinations, or enter number of package");

            var selectPackages = true;

            while (selectPackages)
            {
                string newPackage = (Console.ReadLine() ?? "").Trim();
                if (ReturnLater(newPackage))
                {
                    return(TripStateLoop.Status.Stop);
                }
                int packSelect;
                if (Int32.TryParse(newPackage, out packSelect))
                {
                    if (packSelect > premadePacks.Count || packSelect < 1)
                    {
                        Console.WriteLine("Please enter a valid number");
                        continue;
                    }
                }


                //come back later?
                //if (ReturnLater(newPackage)) return TripStateLoop.Status.Stop;

                else
                {
                    Console.WriteLine("Please enter a valid number");
                }
                //check unique and continue entering
                if (ContinueEnteringDestinations(newPackage))
                {
                    if (IsDestinationValid(newPackage, packSelect - 1))
                    {
                        TripContext.Trip.selectedPacks.Add(premadePacks[packSelect - 1]);
                        Console.WriteLine($"- Added Package [{premadePacks[packSelect-1].ToString()}]");
                    }
                }
                else
                {
                    //stop if we can change state
                    selectPackages = !IsDestinationListValid();
                }
            }

            TripContext.ChangeState(new TripStateChoosePaymentType(TripContext));
            return(TripStateLoop.Status.Continue);
        }
예제 #5
0
        public override TripStateLoop.Status Execute()
        {
            int id = 0;
            int agentNumber;

            Console.WriteLine();
            Console.WriteLine("Please select the agent by entering the number corresponding to the agent");


            for (int x = 0; x < travelAgents.Count; x++)
            {
                Console.WriteLine($"{x + 1}: " + travelAgents[x].ToString());
            }


            //loops to handle user input
            var enterAgentNumber = true;

            while (enterAgentNumber)
            {
                string newAgentNumber = (Console.ReadLine() ?? "").Trim();


                if (Int32.TryParse(newAgentNumber, out agentNumber))
                {
                    if (agentNumber > travelAgents.Count || agentNumber < 1)
                    {
                        Console.WriteLine("Please enter a valid number");
                        continue;
                    }
                    TripContext.Trip.TripAgent = travelAgents[agentNumber - 1];
                    Console.WriteLine($"Welcome {travelAgents[agentNumber -1].name}".ToUpper());
                    break;
                }

                Console.WriteLine("Please enter a valid number");
            }



            Console.WriteLine();
            Console.WriteLine("To view existing trips, enter [yes], to create a new trip hit the enter key");
            Console.WriteLine();

            var chooseExisting = true;

            while (chooseExisting)
            {
                string decision = (Console.ReadLine() ?? "").Trim();

                if (GoToExisting(decision))
                {
                    TripContext.ChangeState(new TripStateHandleExisting(TripContext));
                    return(TripStateLoop.Status.Continue);
                }

                break;
            }

            Console.WriteLine();
            Console.WriteLine("*** NEW TRIP CREATED ***");

            Console.WriteLine(" Enter trip ID for the new trip");

            var enterTripID = true;

            while (enterTripID)
            {
                string newAmount = (Console.ReadLine() ?? "").Trim();

                //int payerNumber = Int32.Parse(Console.ReadLine());
                if (Int32.TryParse(newAmount, out id))
                {
                    TripContext.Trip.tripID = id;
                    break;
                }

                Console.WriteLine("Please enter a valid number");
            }



            Console.WriteLine("Please add travellers to the trip by entering the number corresponding to the person");
            Console.WriteLine();


            for (int x = 0; x < travellers.Count; x++)
            {
                Console.WriteLine($"{x + 1}: " + travellers[x].ToString());
            }


            Console.WriteLine();

            var selectTravellers = true;

            while (selectTravellers)
            {
                string newTraveller = (Console.ReadLine() ?? "").Trim();
                //int packSelect = Int32.Parse(newPackage)-1;

                if (Int32.TryParse(newTraveller, out int travelSelect))
                {
                    if (travelSelect > travellers.Count || travelSelect < 1)
                    {
                        Console.WriteLine("Please enter a valid number");
                        continue;
                    }
                }
                if (ReturnLater(newTraveller))
                {
                    return(TripStateLoop.Status.Stop);
                }
                if (ContinueEnteringDestinations(newTraveller))
                {
                    if (IsDestinationValid(newTraveller, travelSelect - 1))
                    {
                        TripContext.Trip.selectedTravellers.Add(travellers[travelSelect - 1]);
                        Console.WriteLine($"- Added Traveller [{travellers[travelSelect-1].ToString()}]");
                    }
                }
                else
                {
                    //stop if we can change state
                    selectTravellers = !IsDestinationListValid();
                }
            }

            TripContext.ChangeState(new TripStateAddPackages(TripContext));
            return(TripStateLoop.Status.Continue);
        }
예제 #6
0
        public override TripStateLoop.Status Execute()
        {
            int     cardNumber = 0;
            string  expDate;
            decimal amount = 0;

            Console.WriteLine(Environment.NewLine + "*** ACCEPT CARD PAYMENT ***");

            Console.WriteLine("Enter Card Number or [later] to return later");

            var selectCardNumber = true;

            while (selectCardNumber)
            {
                string newCardNumber = (Console.ReadLine() ?? "").Trim();

                //int payerNumber = Int32.Parse(Console.ReadLine());
                if (Int32.TryParse(newCardNumber, out int number))
                {
                    cardNumber = number;
                    break;
                }
                else if (ReturnLater(newCardNumber))
                {
                    return(TripStateLoop.Status.Stop);
                }

                else
                {
                    Console.WriteLine("Please enter a valid number");
                }
            }

            Console.WriteLine("Enter card expiration date (mm/yy) or [later] to return later");

            var inputExpDate = true;

            while (inputExpDate)
            {
                string newExpDate = (Console.ReadLine() ?? "").Trim();

                //int payerNumber = Int32.Parse(Console.ReadLine());

                if (ReturnLater(newExpDate))
                {
                    return(TripStateLoop.Status.Stop);
                }

                else
                {
                    expDate = newExpDate;
                }
                break;
            }

            Console.WriteLine();
            Console.WriteLine($"The total amount for the trip is: ${TripContext.Trip.totalPrice}");
            Console.WriteLine("- Enter amount or [later] to return later");
            Console.WriteLine();

            var enterAmount = true;

            while (enterAmount)
            {
                string newAmount = (Console.ReadLine() ?? "").Trim();

                //int payerNumber = Int32.Parse(Console.ReadLine());
                if (Decimal.TryParse(newAmount, out amount))
                {
                    if (amount > TripContext.Trip.totalPrice)
                    {
                        Console.WriteLine("You are overpaying, we don't need your pity, please re-enter amount");
                        continue;
                    }

                    if (amount < TripContext.Trip.totalPrice)
                    {
                        Console.WriteLine("You are underpaying, please, we are struggling, re-enter amount");
                        continue;
                    }
                }
                else if (ReturnLater(newAmount))
                {
                    return(TripStateLoop.Status.Stop);
                }



                else
                {
                    Console.WriteLine("Please enter a valid number");
                }

                break;
            }


            TripContext.Trip.Payment = new PaymentCard(cardNumber, amount, "02/21)");
            Console.WriteLine($"{TripContext.Trip.Payer} paid {TripContext.Trip.totalPrice} by card");



            TripContext.ChangeState(new TripStateAddThankYou(TripContext));
            return(TripStateLoop.Status.Continue);
        }