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
        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);
        }
Example #4
0
        static void Main(string[] args)
        {
            Person person = new Person();

            person.getAssets().Add(new BankAccount(1000, 0.01));
            person.getAssets().Add(new BankAccount(2000, 0.02));
            person.getAssets().Add(new RealEstate(79000, 500));
            person.getAssets().Add(new Loan(40000, 40));

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

            person.accept(netWorthVisitor);
            person.accept(incomeVisitor);

            Console.WriteLine(netWorthVisitor.getTotal());
            Console.WriteLine(incomeVisitor.getAmount());
        }