예제 #1
0
        public void NotifyTicketCount(object sender, EventArgs e)
        {
            int       ticketCount;
            PiggyBank bank = (PiggyBank)sender;

            ticketCount = (int)(bank.Saldo / unitPrice);

            if (ticketCount > lastCount)
            {
                Console.WriteLine($"Tillykke – du har nu penge nok til {ticketCount} sæsonkort til OBs kampe");
                lastCount = ticketCount;
            }
        }
예제 #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to piggybank inc");

            PiggyBank   bank    = new PiggyBank();
            CoinHandler handler = new CoinHandler();

            bank.RegisterHandler(handler.ShowTotal);
            bank.RegisterHandler(handler.NotifyTicketCount);

            bool   valid, insert = true;
            double amount = 0;

            while (insert == true)
            {
                Console.Write("Enter amount to add to the piggybank: ");
                valid = Double.TryParse(Console.ReadLine(), out amount);
                Console.WriteLine();

                if (valid && amount > 0)
                {
                    bank.InsertCoins(amount);
                }
                else if (valid && amount == 0)
                {
                    insert = false;
                }
                else
                {
                    Console.WriteLine("Invalid input, try again");
                }
                Console.WriteLine();
            }

            Console.WriteLine("Thanks for visiting piggybank inc.");

            Console.ReadKey();
        }
예제 #3
0
파일: Program.cs 프로젝트: antkott/cSharp
        private static void Main(string[] args)
        {
            string    readLine;
            PiggyBank piggyBank = new PiggyBank(550);

            do
            {
                Console.WriteLine();
                Console.WriteLine("How much to deposit?");
                Console.WriteLine(" *type 'exit' for exit");
                readLine = Console.ReadLine();
                if (!readLine.Equals("exit"))
                {
                    int.TryParse(readLine, out int amount);
                    if (0 == amount)
                    {
                        Console.WriteLine("Invalid deposit value");
                        continue;
                    }
                    piggyBank.Balance = amount;
                }
            } while (readLine != "exit");
            Console.WriteLine("  exit..");
        }
예제 #4
0
        public void ShowTotal(object sender, CoinEvent e)
        {
            PiggyBank bank = (PiggyBank)sender;

            Console.WriteLine($"{e.amountAdded} added to the piggybank, new total: {bank.Saldo}");
        }