Beispiel #1
0
        //This here is just our bucket sort for the droids. Places each droid into a matching stack (I used a case structure based around the string instead of typing it)
        //after that, it gets put into a queue, for the sole purpose of showing that... I can write a queue. After that it gets put back into the array.
        //After some early issues I realized that it wasn't working properly due to data entry problems, so maybe using the Type to sort them would have worked better,
        //but by this time I had already finished it with strings.

        public void ModelSort(DroidQueue <IDroid> queue, DroidStack <IDroid> protocolStack, DroidStack <IDroid> janitorStack, DroidStack <IDroid> utilityStack,
                              DroidStack <IDroid> astromechStack)
        {
            for (int counter = 0; counter < droidCollection.GetLength(0); counter++)
            {
                if (this.droidCollection[counter] != null)
                {
                    switch (this.droidCollection[counter].Model)
                    {
                    case "Protocol":
                        protocolStack.AddDroid(this.droidCollection[counter]);
                        break;

                    case "Astromech":
                        astromechStack.AddDroid(this.droidCollection[counter]);
                        break;

                    case "Janitorial":
                        janitorStack.AddDroid(this.droidCollection[counter]);
                        break;

                    case "Utility":
                        utilityStack.AddDroid(this.droidCollection[counter]);
                        break;
                    }
                }
            }



            while (astromechStack.Size != 0)
            {
                queue.QueueDroid(astromechStack.RemoveDroid());
            }

            while (janitorStack.Size != 0)
            {
                queue.QueueDroid(janitorStack.RemoveDroid());
            }

            while (utilityStack.Size != 0)
            {
                queue.QueueDroid(utilityStack.RemoveDroid());
            }

            while (protocolStack.Size != 0)
            {
                queue.QueueDroid(protocolStack.RemoveDroid());
            }
            lengthOfCollection = 0;

            while (queue.Size != 0)
            {
                this.droidCollection[lengthOfCollection] = queue.UnQueueDroid();
                lengthOfCollection++;
            }
        }
Beispiel #2
0
 //Constructor that will take in a droid collection to use
 public UserInterface(IDroidCollection DroidCollection, DroidQueue <IDroid> Queue, DroidStack <IDroid> AstromechStack, DroidStack <IDroid> JanitorStack, DroidStack <IDroid> UtilityStack,
                      DroidStack <IDroid> ProtocolStack)
 {
     this.droidCollection = DroidCollection;
     this.queue           = Queue;
     this.astromechStack  = AstromechStack;
     this.janitorStack    = JanitorStack;
     this.utilityStack    = UtilityStack;
     this.protocolStack   = ProtocolStack;
 }
        static void Main(string[] args)
        {
            //Instanciates some a queue and a stack for each type of droid
            DroidQueue <IDroid> queue          = new DroidQueue <IDroid>();
            DroidStack <IDroid> protocolStack  = new DroidStack <IDroid>();
            DroidStack <IDroid> utilityStack   = new DroidStack <IDroid>();
            DroidStack <IDroid> astromechStack = new DroidStack <IDroid>();
            DroidStack <IDroid> janitorStack   = new DroidStack <IDroid>();

            //Create a new droid collection and set the size of it to 100.
            IDroidCollection droidCollection = new DroidCollection(100);

            //Create a user interface and pass the droidCollection into it as a dependency
            UserInterface userInterface = new UserInterface(droidCollection, queue, astromechStack, janitorStack, utilityStack, protocolStack);


            //Here, have a whole bunch of pre-created droids to use for testing! Some minor typos in these when I first typed em gave me quite a headache.

            droidCollection.Add("Carbonite", "Protocol", "Gold", 7);
            droidCollection.Add("Vanadium", "Protocol", "Silver", 10);
            droidCollection.Add("Vanadium", "Astromech", "Silver", true, false, true, true, 5);
            droidCollection.Add("Carbonite", "Astromech", "Gold", false, true, true, true, 3);
            droidCollection.Add("Carbonite", "Utility", "Gold", false, true, false);
            droidCollection.Add("Vanadium", "Utility", "Silver", true, false, true);
            droidCollection.Add("Carbonite", "Janitorial", "Gold", true, false, true, false, true);
            droidCollection.Add("Vanadium", "Janitorial", "Silver", true, true, false, false, true);


            //Display the main greeting for the program
            userInterface.DisplayGreeting();

            //Display the main menu for the program
            userInterface.DisplayMainMenu();

            //Get the choice that the user makes
            int choice = userInterface.GetMenuChoice();

            //While the choice is not equal to 3, continue to do work with the program
            while (choice != 5)
            {
                //Test which choice was made
                switch (choice)
                {
                //Choose to create a droid
                case 1:
                    userInterface.CreateDroid();
                    break;

                //Choose to Print the droid
                case 2:
                    userInterface.PrintDroidList();
                    break;

                //Choose to Sort by Model
                case 3:
                    userInterface.SortDroidListByModel();
                    break;

                //Choose to sort by cost.
                case 4:
                    userInterface.SortDroidListByCost();
                    break;
                }
                //Re-display the menu, and re-prompt for the choice
                userInterface.DisplayMainMenu();
                choice = userInterface.GetMenuChoice();
            }
        }