desislava_topuzakova

Freight

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