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(); }
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); }
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); }