mitko2204

HUman

Feb 18th, 2021
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4.  
  5. namespace Mankind11b
  6. {
  7. public abstract class Human
  8. {
  9. private string firstName;
  10. private string lastName;
  11.  
  12. public Human(string firstName, string lastName)
  13. {
  14. FirstName = firstName;
  15. LastName = lastName;
  16. }
  17.  
  18. public string FirstName
  19. {
  20. get { return firstName; }
  21. set {
  22. if (!Char.IsUpper(value[0])) //!(value[0]>='A' && value[0]<='Z')
  23. {
  24. throw new ArgumentException("Expected upper case letter! Argument: firstName");
  25. }
  26. if (value.Length < 4)
  27. {
  28. throw new ArgumentException("Expected length at least 4 symbols! Argument: firstName");
  29. }
  30. firstName = value;
  31. }
  32. }
  33.  
  34. public string LastName
  35. {
  36. get { return lastName; }
  37. set {
  38. if (!Char.IsUpper(value[0]))
  39. {
  40. throw new ArgumentException("Expected upper case letter! Argument: lastName");
  41. }
  42. if(value.Length < 3)
  43. {
  44. throw new ArgumentException("Expected length at least 3 symbols! Argument: lastName");
  45. }
  46. lastName = value;
  47. }
  48. }
  49.  
  50. public override string ToString()
  51. {
  52. return $"First Name: {FirstName}\nLast Name: {LastName}";
  53. }
  54. }
  55. }
  56.  
Advertisement
Add Comment
Please, Sign In to add comment