Example #1
0
        private static void Main(string[] args)
        {
            var person = new Person();

            person.Assets.Add(new BankAccount {
                Amount = 1000, MonthlyInterest = 0.01
            });
            person.Assets.Add(new BankAccount {
                Amount = 2000, MonthlyInterest = 0.02
            });
            person.Assets.Add(new RealEstate {
                EstimatedValue = 79000, MonthlyRent = 500
            });
            person.Assets.Add(new Loan {
                Owed = 40000, MonthlyPayment = 40
            });

            var netWorthVisitor = new NetWorthVisitor();
            var incomeVisitor   = new IncomeVisitor();

            person.Accept(netWorthVisitor);
            person.Accept(incomeVisitor);

            Console.WriteLine(netWorthVisitor.Total);
            Console.WriteLine(incomeVisitor.Amount);
            Console.ReadLine();
        }
Example #2
0
        public static void Main(string[] args)
        {
            var person = new Person();

            person.Assets.Add(new RealEstate {
                EstimatedValue = 79000, MonthlyRent = 500
            });
            person.Assets.Add(new BankAccount {
                Amount = 1000, MonthlyInterest = 0.02m
            });
            person.Assets.Add(new BankAccount {
                Amount = 2000, MonthlyInterest = 0.01m
            });
            person.Assets.Add(new Loan {
                Owned = 40000, MonthlyPayment = 400
            });

            var netWorth = new NetWorthVisitor();

            person.Accept(netWorth);
            Console.WriteLine(netWorth.Total);

            var income = new MonthlyIncomeVisitor();

            person.Accept(income);
            Console.WriteLine(income.Total);

            Console.ReadKey();
        }
Example #3
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();
        }
Example #4
0
        private static void NetWorthDemo()
        {
            var person = new Person();

            person.Assets.Add(new BankAccount {
                Amount = 10000, MonthlyInterest = 0.005M
            });
            person.Assets.Add(new BankAccount {
                Amount = 1000, MonthlyInterest = 0.01M
            });
            person.Assets.Add(new RealEstate {
                EstimatedValue = 100000, MonthlyRent = 500
            });
            person.Assets.Add(new Loan {
                Owed = 30000, MonthlyPayment = 300
            });

            var netWorthVisitor = new NetWorthVisitor();

            person.Accept(netWorthVisitor);
            Console.WriteLine("Total value of assets: {0}", netWorthVisitor.Total);

            var monthlyIncomeVisitor = new MonthlyIncomeVisitor();

            person.Accept(monthlyIncomeVisitor);
            Console.WriteLine("Total monthly income: {0}", monthlyIncomeVisitor.Total);
        }