Exemple #1
0
        static void Main(string[] args)
        {
            Makanan biskuit = new Biskuit(10, 6000);
            Makanan chips   = new Chips(10, 8000);
            Makanan oreo    = new Oreo(10, 10000);
            Makanan tango   = new Tango(10, 12000);
            Makanan cokelat = new Cokelat(10, 15000);

            while (true)
            {
                Console.Clear();
                Console.WriteLine("**** Self-service Vending Machine ****");
                Console.WriteLine("1.Biskuit Price 6000");
                Console.WriteLine("2.Chips Price 8000");
                Console.WriteLine("3.Oreo Price 10000");
                Console.WriteLine("4.Tango Price 12000");
                Console.WriteLine("5.Cokelat Price 15000");

                Console.WriteLine("Pilih sesuai angka :");
                int item = int.Parse(Console.ReadLine());

                switch (item)
                {
                case 1:
                    Transaksi(biskuit);
                    break;

                case 2:
                    Transaksi(chips);
                    break;

                case 3:
                    Transaksi(oreo);
                    break;

                case 4:
                    Transaksi(tango);
                    break;

                case 5:
                    Transaksi(cokelat);
                    break;
                }
            }
        }
Exemple #2
0
        internal void BuyItems(List <IProduct> purchasedProducts)
        {
            int  options = aviableProducts.Count;
            bool exit    = false;

            do
            {
                keyInfo = Console.ReadKey(true);

                if (Char.IsDigit(keyInfo.KeyChar))
                {
                    int choice = Int32.Parse(keyInfo.KeyChar.ToString());

                    if (choice <= options && choice >= 1)
                    {
                        IProduct newProduct = null;
                        if (aviableProducts[choice - 1] is Soda)
                        {
                            newProduct = new Soda()
                            {
                                Price = aviableProducts[choice - 1].Price
                            };
                        }
                        if (aviableProducts[choice - 1] is Chips)
                        {
                            newProduct = new Chips()
                            {
                                Price = aviableProducts[choice - 1].Price
                            };
                        }
                        if (aviableProducts[choice - 1] is Candybar)
                        {
                            newProduct = new Candybar()
                            {
                                Price = aviableProducts[choice - 1].Price
                            };
                        }

                        if (newProduct.Purchase(CurrentDepositedMoney))
                        {
                            purchasedProducts.Add(newProduct);
                            CurrentDepositedMoney -= newProduct.Price;
                        }
                        else
                        {
                            Console.WriteLine("You have not deposited enough money to buy that item");
                            continue;
                        }

                        ConsoleKey response;
                        do
                        {
                            Console.WriteLine($"You bought some {newProduct.GetType().Name}");
                            Console.Write("Do you wish to use this product now? (y/n)");
                            response = Console.ReadKey(false).Key;
                            if (response != ConsoleKey.Enter)
                            {
                                Console.WriteLine();
                            }
                        } while (response != ConsoleKey.Y && response != ConsoleKey.N);

                        if (response == ConsoleKey.Y)
                        {
                            newProduct.Use();
                            purchasedProducts.Remove(newProduct);
                        }
                        break;
                    }
                }

                if (keyInfo.Key != ConsoleKey.Enter)
                {
                    Console.WriteLine();
                }
                exit = keyInfo.Key == ConsoleKey.X;
            } while (!exit);
        }
Exemple #3
0
        static void Main(string[] args)
        {
            int moneyPool = 0;

            string[] article = { "Kaffe", "Thè", "Cola", "Ost Sandwich", "Skink Sandwich", "Tonfisk-Sandwich", "Chips", "Popcorn", "Jordnötter" };

            Checkout checkout = new Checkout();

            //Init all products
            Coffee         coffee         = new Coffee(15);
            Tea            tea            = new Tea(10);
            Cola           cola           = new Cola(20);
            CheeseSandwich cheeseSandwich = new CheeseSandwich(20);
            HamSandwich    hamSandwich    = new HamSandwich(25);
            TunaSandwich   tunaSanwich    = new TunaSandwich(35);
            Chips          chips          = new Chips(30);
            Popcorn        popcorn        = new Popcorn(25);
            Peanuts        peanuts        = new Peanuts(25);

            Console.WriteLine("Välkommen!");                        //Greetings

            Console.WriteLine("Var god mata in pengar.");           //Put money into moneyPool

            do
            {
                var input = Console.ReadLine();
                try
                {
                    moneyPool = Int32.Parse(input);
                }
                catch (FormatException)
                {
                    Console.WriteLine($"You entered '{input}' and it needs to be '1,2,3...,n-1,n '");
                }
                Console.WriteLine($"Du har {moneyPool} kronor att handla för.");
                if (moneyPool < 1)
                {
                    Console.WriteLine("Lägg till pengar. Ange belopp: ");
                }
                else
                {
                    break;
                }
            } while (moneyPool < 1);


            Console.WriteLine("Meny");                              //Print menu
            Console.WriteLine("---------------------------------------------------------------");
            for (int i = 0; i < article.Length; i++)
            {
                Console.WriteLine($"Välj {i + 1}: för {article[i]}");
            }

            do     //Loop for multiple choice of items
            {
                Console.WriteLine("Var god välj vara (nummer 1-9) eller (0) för att avsluta: ");
                int    choice = 0;
                string input  = Console.ReadLine();

                try
                {
                    choice = Int32.Parse(input);
                }
                catch (FormatException)
                {
                    Console.WriteLine($"You entered '{input}' and it needs to be '1,2,3...,n-1,n '");
                }

                if (choice == 0)
                {
                    break;
                }
                switch (choice)
                {
                case 1:

                    moneyPool = coffee.Purchase(moneyPool);
                    Console.WriteLine($"Du har {moneyPool} kronor kvar att handla för.");
                    break;

                case 2:

                    moneyPool = tea.Purchase(moneyPool);
                    Console.WriteLine($"Du har {moneyPool} kronor kvar att handla för.");
                    break;

                case 3:

                    moneyPool = cola.Purchase(moneyPool);
                    Console.WriteLine($"Du har {moneyPool} kronor kvar att handla för.");
                    break;

                case 4:

                    moneyPool = cheeseSandwich.Purchase(moneyPool);
                    Console.WriteLine($"Du har {moneyPool} kronor kvar att handla för.");
                    break;

                case 5:

                    moneyPool = hamSandwich.Purchase(moneyPool);
                    Console.WriteLine($"Du har {moneyPool} kronor kvar att handla för.");
                    break;

                case 6:

                    moneyPool = tunaSanwich.Purchase(moneyPool);
                    Console.WriteLine($"Du har {moneyPool} kronor kvar att handla för.");
                    break;

                case 7:

                    moneyPool = chips.Purchase(moneyPool);
                    Console.WriteLine($"Du har {moneyPool} kronor kvar att handla för.");
                    break;

                case 8:

                    moneyPool = popcorn.Purchase(moneyPool);
                    Console.WriteLine($"Du har {moneyPool} kronor kvar att handla för.");
                    break;

                case 9:

                    moneyPool = peanuts.Purchase(moneyPool);
                    Console.WriteLine($"Du har {moneyPool} kronor kvar att handla för.");
                    break;

                default:

                    break;
                }
            } while (true);

            checkout.PayBackMoney(moneyPool);          //Refund or give change back
            Console.WriteLine();
        }
Exemple #4
0
        public override Product Buy(int priceIn, string nameIn)
        {
            Chips soda = new Chips();

            return(soda);
        }