Example #1
0
        static void Main(string[] args)
        {
            List <IRentable>    RentOptions     = new List <IRentable>();
            List <IPurchasable> PurchaseOptions = new List <IPurchasable>();

            var vehicle = new VehicleModel {
                DealerFee = 88, ProductName = "Hertz Rentals", QuantityInStock = 100
            };
            var book = new BookModel {
                PageNumber = 888888, ProductName = "Ayn Rand Omnibus and Analysis", QuantityInStock = 666
            };
            var excavator = new ExcavatorModel {
                ProductName = "CAT", QuantityInStock = 88
            };

            RentOptions.Add(vehicle);
            RentOptions.Add(book);
            RentOptions.Add(excavator);

            PurchaseOptions.Add(book);
            PurchaseOptions.Add(vehicle);

            Console.Write("Do you want to rent or purchase something: (rent, purchase) ");
            string rentalChoice = Console.ReadLine();

            if (rentalChoice.ToLower() == "rent")
            {
                foreach (var selection in RentOptions)
                {
                    Console.WriteLine($"Item: { selection.ProductName }");
                    Console.Write("Care to rent this item? (yes/no): ");
                    string rentTho = Console.ReadLine();

                    if (rentTho.ToLower() == "yes")
                    {
                        selection.Rent();
                    }


                    Console.Write("Care to return this item? (yes/no): ");
                    string returnTho = Console.ReadLine();

                    if (returnTho.ToLower() == "yes")
                    {
                        selection.ReturnRental();
                    }
                }
            }
            else if (rentalChoice.ToLower() == "purchase")
            {
                foreach (var obj in PurchaseOptions)
                {
                    Console.Write("Care to purchase this item? (yes/no): ");
                    string buyThis = Console.ReadLine();

                    if (buyThis.ToLower() == "yes")
                    {
                        obj.Purchase();
                    }
                }
            }
            Console.ReadLine();
        }
Example #2
0
        static void Main(string[] args)
        {
            //List<InventoryItemModel> inventory = new List<InventoryItemModel>();
            //inventory.Add(new VehicleModel { DealerFee = 25, ProductName = "Ford Gold" });
            //inventory.Add(new BookModel { NumOfPages = 300, ProductName = "La Bella y la Bestia" });


            List <IPurchasable> purchasables = new List <IPurchasable>();
            List <IRentable>    rentables    = new List <IRentable>();

            var vehicle = new VehicleModel {
                DealerFee = 25, ProductName = "Ford Gold"
            };
            var book = new BookModel {
                NumOfPages = 300, ProductName = "La Bella y la Bestia"
            };
            var excavator = new ExcavatorModel {
                ProductName = "Bulldozer", QuantityInStock = 2
            };

            rentables.Add(vehicle);
            rentables.Add(excavator);

            purchasables.Add(book);
            purchasables.Add(vehicle);

            Console.WriteLine("Do you want to rent or purchase something? Chosee purchase / rent");
            string rentalDesicion = Console.ReadLine();

            if (rentalDesicion.ToLower() == "rent")
            {
                foreach (var item in rentables)
                {
                    Console.WriteLine($"Iem: {item.ProductName}");
                    Console.Write("Do you want to rent this item? yes/no");
                    string wantToRent = Console.ReadLine();

                    if (wantToRent.ToLower() == "yes")
                    {
                        item.Rent();
                    }

                    Console.Write("Do you want to return this item? yes/no");
                    string wantToReturn = Console.ReadLine();

                    if (wantToReturn.ToLower() == "yes")
                    {
                        item.ReturnRental();
                    }
                }
            }
            else
            {
                foreach (var item in purchasables)
                {
                    Console.WriteLine($"Item: {item.ProductName}");
                    Console.Write("Do you want to purchase this item? yes/no");
                    string wantToPurchase = Console.ReadLine();

                    if (wantToPurchase.ToLower() == "yes")
                    {
                        item.Purchase();
                    }
                }

                Console.ReadLine();
            }
        }