Exemple #1
0
        private static ToyBox GetNewToyBoxFromUser()
        {
            Console.WriteLine("Enter the location of the toybox.");
            string loc = Console.ReadLine();

            Console.WriteLine("Enter the owner of the toybox.");
            string owner = Console.ReadLine();

            ToyBox box = new ToyBox()
            {
                Location = loc,
                Owner    = owner
            };

            return(box);
        }
Exemple #2
0
        static void Main(string[] args)
        {
            List <ToyBox> toyboxes = new List <ToyBox>();
            string        UserAnswer;

            Console.WriteLine("Please add a toybox.");
            do
            {
                ToyBox newToyBox = GetNewToyBoxFromUser();
                toyboxes.Add(newToyBox);
                Console.WriteLine("Do you want to add another toybox? yes or no>>");
                UserAnswer = Console.ReadLine();
            } while (UserAnswer.ToLower() == "yes");


            string answer;

            foreach (ToyBox toyBox in toyboxes)
            {
                Console.WriteLine($"Time to fill {toyBox.Owner}'s Toy Box!");
                do
                {
                    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!");
            Console.WriteLine();
            foreach (ToyBox toyBox in toyboxes)
            {
                Console.WriteLine($"Content of {toyBox.Owner}'s ToyBox!");
                foreach (Toy toy in toyBox.Toys)
                {
                    Console.WriteLine(toy);
                }
            }

            foreach (ToyBox TB in toyboxes)
            {
                Console.WriteLine($"{TB.GetRandomToy().Name}");
            }
        }
        static void Main(string[] args)
        {
            string ans1;

            string        ans;
            List <ToyBox> toyBoxes = new List <ToyBox>();

            do
            {
                Console.WriteLine("Who is the owner of the toybox?");
                string owner = Console.ReadLine();

                Console.WriteLine("Where is the toybox located?");
                string location = Console.ReadLine();

                ToyBox tb = new ToyBox();
                tb.Owner    = owner;
                tb.Location = location;

                toyBoxes.Add(tb);

                Console.WriteLine("Would you like to add a toybox?");
                ans = Console.ReadLine().ToLower();
            } while (ans[0] == 'y');



            foreach (ToyBox tb in toyBoxes)
            {
                Console.WriteLine($"Let's add to {tb.Owner}'s toybox");

                do
                {
                    Console.WriteLine("Who manufactured the toy?");
                    string manufact = Console.ReadLine();

                    Console.WriteLine("What is the name of the toy?");
                    string name = Console.ReadLine();

                    Console.WriteLine("How much did the toy cost?");
                    double price = Convert.ToDouble(Console.ReadLine());

                    Console.WriteLine("Are there any notes about this toy?");
                    string ans2 = Console.ReadLine().ToLower();
                    string notes;
                    if (ans2[0] == 'y')
                    {
                        Console.WriteLine("What notes do you have?");
                        notes = Console.ReadLine();
                    }
                    else
                    {
                        notes = "";
                    }
                    Toy t = new Toy();
                    t.Manufacturer = manufact;
                    t.Name         = name;
                    t.Price        = price;
                    t.AddNote(notes);

                    tb.Toys.Add(t);

                    Console.WriteLine("Do you want to add another toy?");
                    ans1 = Console.ReadLine().ToLower();
                } while (ans1[0] == 'y');
            }

            foreach (ToyBox tb in toyBoxes)
            {
                Console.WriteLine($"{tb.Owner}'s toybox contents:");
                foreach (Toy toy in tb.Toys)
                {
                    Console.WriteLine(toy);
                }
            }

            foreach (ToyBox tb in toyBoxes)
            {
                tb.GetRandomToy();
            }
        }