Example #1
0
        public void Run()
        {
            bool done = false;

            while (!done)
            {
                DisplayStatus();
                SkiAction choice = GetNextAction();
                switch (choice)
                {
                case SkiAction.AddSkier:
                    string name;
                    do
                    {
                        Console.Write("Skier's name: ");
                        name = Console.ReadLine();
                    }while(name.Length == 0);
                    Skier newSkier = new Skier(name);
                    _theLift.Enqueue(newSkier);
                    break;

                case SkiAction.RemoveSkier:
                    if (_theLift.Count == 0)
                    {
                        Console.WriteLine("The lift is empty.");
                    }
                    else
                    {
                        Skier nextSkier = (Skier)_theLift.Dequeue();
                        Console.WriteLine("{0} has left the ski lift.",
                                          nextSkier.Name);
                    }

                    break;

                case SkiAction.Quit:
                    Console.WriteLine("Goodbye.");
                    done = true;
                    break;

                default:
                    break;
                }
            }
        }
Example #2
0
        protected void DisplayStatus()
        {
            Console.WriteLine("There are currently {0} skiers on the lift.",
                              _theLift.Count);
            if (_theLift.Count > 0)
            {
                Skier nextSkier = (Skier)_theLift.Peek();
                Console.WriteLine("The next skier will be {0}.",
                                  nextSkier.Name);

                Console.WriteLine("Skiers on the lift:");
                Array skiers = _theLift.ToArray();
                foreach (Skier aSkier in skiers)
                {
                    Console.WriteLine("\t" + aSkier.Name);
                }
            }
        }
Example #3
0
        public void Run()
        {
            bool done = false;
            while(!done)
            {
                DisplayStatus();
                SkiAction choice = GetNextAction();
                switch(choice)
                {
                    case SkiAction.AddSkier:
                        string name;
                        do
                        {
                            Console.Write("Skier's name: ");
                            name = Console.ReadLine();
                        }while(name.Length == 0);
                        Skier newSkier = new Skier(name);
                        _theLift.Enqueue(newSkier);
                        break;

                    case SkiAction.RemoveSkier:
                        if(_theLift.Count == 0)
                        {
                            Console.WriteLine("The lift is empty.");
                        }
                        else
                        {
                            Skier nextSkier = (Skier)_theLift.Dequeue();
                            Console.WriteLine("{0} has left the ski lift.",
                                nextSkier.Name);
                        }
                    
                        break;

                    case SkiAction.Quit:
                        Console.WriteLine("Goodbye.");
                        done = true;
                        break;

                    default:
                        break;
                }
            }
        }