Advertisement
Prohause

PersonClass

Apr 1st, 2019
1,115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. using System.Collections.Generic;
  2. using System.Linq;
  3.  
  4. namespace BankAccount
  5. {
  6. public class StartUp
  7. {
  8. private static void Main(string[] args)
  9. {
  10. //Person person = new Person();
  11. //person.Name = "Pesho";
  12. //person.Age = 23;
  13.  
  14. //Person person2 = new Person();
  15. //person2.Name = "Stamat";
  16. //person2.Age = 33;
  17. //Person person3 = new Person();
  18. //person3.Name = "Gosho";
  19. //person3.Age = 11;
  20. //BankAccount bankAccount = new BankAccount();
  21. //person.GetBalance();
  22. }
  23. }
  24.  
  25. public class BankAccount
  26. {
  27. private int id;
  28. private decimal balance;
  29.  
  30. public int ID
  31. {
  32. get { return id; }
  33. set { id = value; }
  34. }
  35.  
  36. public decimal Balance
  37. {
  38. get { return balance; }
  39. set { balance = value; }
  40. }
  41. }
  42.  
  43. public class Person
  44. {
  45. private string name;
  46. private int age;
  47. private List<BankAccount> accounts;
  48.  
  49. public Person(string name, int age)
  50. {
  51. this.name = name;
  52. this.age = age;
  53. accounts = new List<BankAccount>();
  54. }
  55.  
  56. public Person(string name, int age, List<BankAccount> accounts)
  57. {
  58. this.name = name;
  59. this.age = age;
  60. this.accounts = accounts;
  61. }
  62.  
  63. public List<BankAccount> Accounts
  64. {
  65. get { return accounts; }
  66. set { accounts = value; }
  67. }
  68.  
  69. public int Age
  70. {
  71. get { return age; }
  72. set { age = value; }
  73. }
  74.  
  75. public string Name
  76. {
  77. get { return name; }
  78. set { name = value; }
  79. }
  80.  
  81. public decimal GetBalance()
  82. {
  83. return accounts.Sum(x => x.Balance);
  84. }
  85. }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement