예제 #1
0
        static void Main(string[] args)
        {
            var storemanager = new StoreManager();

            storemanager.AddStorage(new PersistentStore());
            storemanager.AddBookProduct("Maki", 200, 342);
            storemanager.AddBookProduct("Makos", 345, 341);
            storemanager.AddCDProduct("Lajhar Lajko", 546, 12);
            storemanager.AddCDProduct("Lajhar", 345, 12);
            Console.WriteLine(storemanager.ListProducts());
            Console.WriteLine(storemanager.GetTotalProductPrice());
        }
예제 #2
0
        static bool Choose()
        {
            string input = Console.ReadLine();

            switch (input)
            {
            case "1":
                Console.WriteLine();
                storeManager.AddBookProduct(AnyInput("The name of the book: "), JustNumber("The price of the book: "), JustNumber("Number of pages: "));
                return(true);

            case "2":
                Console.WriteLine();
                storeManager.AddCDProduct(AnyInput("The name of the CD: "), JustNumber("The price of the CD: "), JustNumber("Number of tracks: "));
                return(true);

            case "3":
                Console.Clear();
                Console.WriteLine("Store inventory list");
                Console.WriteLine();
                Console.WriteLine("Type          Title                           Size           Price");
                Console.WriteLine("------------------------------------------------------------------");

                foreach (Product product in storeManager.ListProducts())
                {
                    if (product is BookProduct)
                    {
                        Console.Write("Book  ");
                        BookProduct book = (BookProduct)product;
                        Console.Write(book.name.PadRight(40));
                        string pages = book.numOfPages.ToString() + " pages";
                        Console.Write(pages.PadRight(15));
                        string price = book.price.ToString() + " $";
                        Console.WriteLine(price.PadLeft(5));
                    }
                    else
                    {
                        Console.Write("CD    ");
                        CDProduct cd = (CDProduct)product;
                        Console.Write(cd.name.PadRight(40));
                        string tracks = cd.numOfTracks.ToString() + " tracks";
                        Console.Write(tracks.PadRight(15));
                        string price = cd.price.ToString() + " $";
                        Console.WriteLine(price.PadLeft(5));
                    }
                }
                Console.WriteLine();
                AnyInput("Press any key to continue...");
                return(true);

            case "4":
                Console.WriteLine();
                Console.WriteLine("The value of all products in the store: " + Convert.ToString(storeManager.GetTotalProductPrice()) + " $.");
                AnyInput("Press any key to continue...");
                return(true);

            case "0":
                return(false);

            default:
                return(true);
            }
        }