Advertisement
Guest User

Untitled

a guest
Dec 27th, 2014
361
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8.  
  9. class Computer
  10. {
  11. private string name;
  12. private List<Component> components;
  13. private float price;
  14.  
  15. public string Name
  16. {
  17. get
  18. {
  19. return this.name;
  20. }
  21. set
  22. {
  23. if (string.IsNullOrEmpty(value))
  24. {
  25. throw new ArgumentException("Computer name is mandatory");
  26. }
  27. else
  28. {
  29. this.name = value;
  30. }
  31. }
  32. }
  33. public List<Component> Components
  34. {
  35. get
  36. {
  37. return this.components;
  38. }
  39. set
  40. {
  41. if (value == null) throw new ArgumentException("Components are mandatory");
  42. else this.components = value;
  43. }
  44. }
  45. public float Price
  46. {
  47. get
  48. {
  49. return this.price;
  50. }
  51. private set
  52. {
  53. float totalPrice = 0;
  54. foreach(Component component in this.components)
  55. {
  56. totalPrice += component.Price;
  57. }
  58. this.price = totalPrice;
  59. }
  60. }
  61.  
  62. public Computer(string name, List<Component> components)
  63. {
  64. this.Name = name;
  65. this.Components = components;
  66. }
  67. public override string ToString()
  68. {
  69. string output = "";
  70. output += "Computer name: " + this.name + "\n";
  71. foreach(Component component in this.components)
  72. {
  73. string temp = component.ToString();
  74. output += temp + "\n";
  75. }
  76. string priceString = string.Format("{0:C}", this.Price, CultureInfo.CreateSpecificCulture("bg-BG"));
  77. output += priceString + "\n";
  78. return string.Format(output);
  79. }
  80.  
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement