Advertisement
desislava_topuzakova

Hat.cs

May 28th, 2023
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4.  
  5. namespace RegularExam
  6. {
  7. internal class Hat
  8. {
  9. private string type;
  10. private string color;
  11. private double price;
  12.  
  13. public Hat(string type, string color, double price)
  14. {
  15. Type = type;
  16. Color = color;
  17. Price = price;
  18. }
  19.  
  20. public string Type
  21. {
  22. get { return type; }
  23. set { type = value; }
  24. }
  25. public string Color
  26. {
  27. get { return color; }
  28. set { color = value; }
  29. }
  30. public double Price
  31. {
  32. get { return price; }
  33. set
  34. {
  35. if (value > 100)
  36. {
  37. throw new ArgumentException("Invalid hat price!");
  38. }
  39. price = value;
  40. }
  41. }
  42.  
  43. public override string ToString()
  44. {
  45. return $"Hat {type} with color {color} costs {price:F2}";
  46. }
  47. }
  48. }
  49.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement