コード例 #1
0
        private static List <ToyBox> PopulateToyBox()
        {
            List <ToyBox> tbs = new List <ToyBox>();
            ToyBox        tb1 = new ToyBox();

            tb1.Owner    = "Adam";
            tb1.Location = "Price Hall";
            Toy t1 = new Toy("Testing")
            {
                Manufacturer = "Price",
                Name         = "Slinky",
                Price        = 4.99
            };

            tb1.Toys.Add(t1);

            tbs.Add(tb1);

            return(tbs);
        }
コード例 #2
0
        static void Main(string[] args)
        {
            List <ToyBox> boxes = new List <ToyBox>();

            string answer;

            do
            {
                ToyBox toyBox = new ToyBox();

                Console.WriteLine("Who owns this Toy Box? >>");
                toyBox.Owner = Console.ReadLine();
                Console.WriteLine($"Where is this Toy Box located? >>");
                toyBox.Location = Console.ReadLine();

                do
                {
                    Toy toy = new Toy();

                    Console.WriteLine("What is the name of the toy in this box? >>");
                    toy.Name = Console.ReadLine();
                    Console.WriteLine("Who is its manufacturer? >>");
                    toy.Manufacturer = Console.ReadLine();
                    Console.WriteLine("What is its price? >> ");
                    toy.Price = Convert.ToDouble(Console.ReadLine());
                    Console.WriteLine("Toy note / description >>");
                    toy.SetNote(Console.ReadLine());
                    toyBox.Toys.Add(toy);

                    Console.WriteLine("Is there another toy in this box? >>");
                    answer = Console.ReadLine().ToLower();
                } while (answer[0] == 'y');

                boxes.Add(toyBox);

                Console.WriteLine("Do you have another Toy Box? >>");
                answer = Console.ReadLine().ToLower();
            } while (answer[0] == 'y');

            //outputs all toybox and toy info
            foreach (var box in boxes)
            {
                Console.WriteLine(box);
                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine("It holds the following items:");
                Console.ForegroundColor = ConsoleColor.White;

                foreach (var toy in box.Toys)
                {
                    Console.WriteLine(toy);
                    Console.WriteLine();
                }
            }

            //generate random toy from each box
            Console.WriteLine();
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("The following are a random toy from each toy box:");
            foreach (var box in boxes)
            {
                Console.WriteLine(box);
                Toy r = box.GetRandomToy();
                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine(r);
                Console.WriteLine();
            }
        }
コード例 #3
0
        static void Main(string[] args)
        {
            List <ToyBox> toyboxes = new List <ToyBox>();


            string response = string.Empty;

            do
            {
                Console.WriteLine("What is the location of your ToyBox");
                string location = Console.ReadLine();

                Console.WriteLine("Who is the owner of your ToyBox");
                string owner = Console.ReadLine();

                ToyBox tb1 = new ToyBox()
                {
                    Location = location,
                    Owner    = owner
                };

                toyboxes.Add(tb1);

                Console.WriteLine("Do you want to start a new toybox");
                response = Console.ReadLine();
            } while (response.ToLower() == "yes");

            string answer = string.Empty;

            foreach (ToyBox toyBox in toyboxes)
            {
                do
                {
                    Console.WriteLine($"Time to fill {toyBox.Owner}'s Toy Box!");

                    Toy newToy = GetNewToyFromUser();
                    toyBox.Toys.Add(newToy);

                    Console.WriteLine("Do you want to enter another toy? yes or no");
                    answer = Console.ReadLine();
                } while (answer.ToLower() == "yes");
            }



            Console.WriteLine("Time to take a look at all your toys");

            foreach (ToyBox toyBox in toyboxes)
            {
                Console.WriteLine($"Content of {toyBox.Owner}'s ToyBox!");

                foreach (Toy toy in toyBox.Toys)
                {
                    Console.WriteLine($"\n{toy.Name} was made by {toy.Manufacturer} and cost {toy.Price} on {toy.GetAisle()} and has these notes {toy.GetNotes()}");
                }
            }

            foreach (ToyBox TB in toyboxes)
            {
                Console.WriteLine($"\n{TB.GetRandomToy().Name}");
            }
        }