Exemplo n.º 1
0
        static void Main(string[] args)
        {
            SoftwareEngineer se = new SoftwareEngineer();

            se.Incomes.Add(new Salary
            {
                MonthlySalary = 70000,
                TaxApplicable = 0.10
            });
            se.Incomes.Add(new Share
            {
                MonthlyTransaction = 5000,
                TaxApplicable      = 0.20
            });
            se.Incomes.Add(new Training
            {
                MonthlySalary = 30000,
                TaxApplicable = 0.15
            });

            MonthlyIncomeVisitor monthlyIncomeVisitor = new MonthlyIncomeVisitor();

            se.Accept(monthlyIncomeVisitor);


            Console.WriteLine("Monthly Income of Software Engineer is {0}", monthlyIncomeVisitor.MonthlyIncome);

            TaxVisitor taxVisitor = new TaxVisitor();

            se.Accept(taxVisitor);
            Console.WriteLine("Tax applicable is {0}", taxVisitor.Tax);
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            var person = new Person("Wolfgang", 28);

            person.Assets.Add(new Salary {
                SalaryBeforeTax = 10000
            });
            person.Assets.Add(new Salary {
                SalaryBeforeTax = 300
            });
            person.Assets.Add(new Bonus {
                Revenue = 30000
            });
            person.Assets.Add(new Marketing {
                MarketingCosts = 5000
            });

            var totalSalaryVisitor = new TotalSalaryVisitor();
            var taxVisitor         = new TaxVisitor();

            person.Accept(totalSalaryVisitor);
            person.Accept(taxVisitor);

            Console.WriteLine($"The total salary of {person.Name} is {totalSalaryVisitor.TotalSalary}");
            Console.WriteLine($"{person.Name} pays {taxVisitor.Taxes} taxes");

            Console.ReadLine();
        }
Exemplo n.º 3
0
        private static void Main(string[] args)
        {
            Tobacco tobacco = new Tobacco(10.99);
            Alcohol alcohol = new Alcohol(10.99);
            Food    food    = new Food(10.99);

            TaxVisitor taxVisitor = new TaxVisitor();

            double tobaccoTax = tobacco.Accept(taxVisitor);
            double alcoholTax = alcohol.Accept(taxVisitor);
            double foodTax    = food.Accept(taxVisitor);

            Console.WriteLine(string.Format($"Tobacco: price: {tobacco.Price}, tax: {tobaccoTax}"));
            Console.WriteLine(string.Format($"Alcohol: price: {alcohol.Price}, tax: {alcoholTax}"));
            Console.WriteLine(string.Format($"Food: price: {food.Price}, tax: {foodTax}"));
        }