desislava_topuzakova

Truck

May 9th, 2021
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4.  
  5. namespace demo
  6. {
  7. class Truck
  8. {
  9. //име, товароносимост и списък с товари
  10. //валидации:
  11. //1. името не трябва да е празно -> Name cannot be empty
  12. //2. товаримостта не трябава да е < 0 -> Weight cannot be negative
  13. private string name;
  14. private int freightness;
  15. private List<Freight> freights;
  16.  
  17. //конструктор
  18. public Truck(string name, int freightness)
  19. {
  20. this.Name = name;
  21. this.Freightness = freightness;
  22. this.freights = new List<Freight>();
  23.  
  24. }
  25.  
  26. //get и set за name
  27. public string Name
  28. {
  29. get { return this.name; }
  30. set
  31. {
  32. //валидация на стойността
  33. if (string.IsNullOrEmpty(value))
  34. {
  35. Console.WriteLine("Name cannot be empty");
  36. }
  37. else
  38. {
  39. this.name = value;
  40. }
  41. }
  42. }
  43.  
  44. //get и set за freightness
  45. public int Freightness
  46. {
  47. get { return this.freightness; }
  48. set
  49. {
  50. if (value < 0)
  51. {
  52. Console.WriteLine("Weight cannot be negative");
  53. }
  54. else
  55. {
  56. this.freightness = value;
  57. }
  58. }
  59. }
  60.  
  61.  
  62. //get за List<Freight>
  63.  
  64. public List<Freight> Freights
  65. {
  66. get { return this.freights; }
  67. }
  68.  
  69. }
  70. }
  71.  
Advertisement
Add Comment
Please, Sign In to add comment