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..");
        }
        public void ShowTotal(object sender, CoinEvent e)
        {
            PiggyBank bank = (PiggyBank)sender;

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