Advertisement
osman1997

Untitled

Mar 2nd, 2021
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.66 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ClassBoxData
  4.  
  5. {
  6. public class StartUp
  7. {
  8. static void Main(string[] args)
  9. {
  10.  
  11.  
  12. try
  13. {
  14. double length = double.Parse(Console.ReadLine());
  15. double width = double.Parse(Console.ReadLine());
  16. double height = double.Parse(Console.ReadLine());
  17. Box box = new Box(length, width, height);
  18.  
  19. Console.WriteLine($"Surface area = {box.SurfaceArea():f2}");
  20. Console.WriteLine($"Lateral Surface Area - {box.LateralSurfaceArea():f2}");
  21. Console.WriteLine($"Volume - {box.Volume():f2}");
  22. }
  23. catch(ArgumentException ex)
  24. {
  25. Console.WriteLine(ex.Message);
  26. }
  27. }
  28. }
  29. }
  30. using System;
  31. using System.Collections.Generic;
  32. using System.Text;
  33.  
  34. namespace ClassBoxData
  35. {
  36. public class Box
  37. {
  38. private double length;
  39. private double width;
  40. private double height;
  41.  
  42. public Box(double length, double width, double height)
  43. {
  44. this.Length = length;
  45. this.Width = width;
  46. this.Height = height;
  47. }
  48.  
  49.  
  50. public double Length
  51. {
  52. get => this.length;
  53. private set
  54. {
  55. this.ThrowIfIsRangeNumbers(value, nameof(this.Length));
  56.  
  57. this.length = value;
  58. }
  59. }
  60.  
  61. public double Width
  62. {
  63. get => this.width;
  64. private set
  65. {
  66. this.ThrowIfIsRangeNumbers(value, nameof(this.Width));
  67. this.width = value;
  68. }
  69. }
  70. public double Height
  71. {
  72. get => this.height;
  73. private set
  74. {
  75. this.ThrowIfIsRangeNumbers(value, nameof(this.Height));
  76. this.height = value;
  77. }
  78. }
  79.  
  80. public double Volume()
  81. {
  82. double res = this.Length * this.Width * this.Height;
  83. return res;
  84. }
  85.  
  86. public double SurfaceArea()
  87. {
  88. return 2 * this.Length * this.Width + 2 * this.Length * this.Height + 2 * this.Width * this.Height;
  89. }
  90.  
  91. public double LateralSurfaceArea()
  92. {
  93. return 2 * this.Length * this.Height + 2 * this.Width * this.Height;
  94. }
  95.  
  96. private void ThrowIfIsRangeNumbers(double value, string side)
  97. {
  98. if (value <= 0)
  99. {
  100. throw new ArgumentException($"{side} cannot be zero or negative.");
  101. }
  102. }
  103. }
  104. }
  105.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement