Advertisement
Mitax

Boxes

Mar 23rd, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.37 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _5.Boxes
  8. {
  9. public class Box
  10. {
  11. public int UpperLeft { get; set; }
  12. public int UpperRight { get; set; }
  13. public int BottomLeft { get; set; }
  14. public int BottomRight { get; set; }
  15. public int Perimeter { get; set; }
  16. public int Area { get; set; }
  17. public int Width { get; set; }
  18. public int Height { get; set; }
  19.  
  20. public static int CalculatePerimeter(int width, int height)
  21. {
  22. return width * 2 + height * 2;
  23. }
  24.  
  25. public static int CalculateArea(int width, int height)
  26. {
  27. return width * height;
  28. }
  29. }
  30.  
  31. class Boxes
  32. {
  33. static void Main(string[] args)
  34. {
  35. var boxes = new List<Box>();
  36. var line = Console.ReadLine();
  37.  
  38. while (line != "end")
  39. {
  40. string[] inputParams = line.Split(new[] { ' ', '|',':' }, StringSplitOptions.RemoveEmptyEntries);
  41.  
  42. int upperLeft = int.Parse(inputParams[0]);
  43. int upperRight = int.Parse(inputParams[1]);
  44. int bottomLeft = int.Parse(inputParams[2]);
  45. int bottomRight = int.Parse(inputParams[3]);
  46.  
  47. int width = Math.Abs(upperLeft - upperRight);
  48. int height = Math.Abs(upperLeft - bottomLeft);
  49.  
  50. var area = Box.CalculateArea(width, height);
  51. var perimeter = Box.CalculatePerimeter(width, height);
  52.  
  53. Box newBox = new Box
  54. {
  55. UpperLeft = upperLeft,
  56. UpperRight = upperRight,
  57. BottomLeft = bottomLeft,
  58. BottomRight = bottomRight,
  59. Area = area,
  60. Perimeter = perimeter,
  61. Width = width,
  62. Height = height
  63. };
  64.  
  65. boxes.Add(newBox);
  66. line = Console.ReadLine();
  67. }
  68.  
  69. foreach (var box in boxes)
  70. {
  71. Console.WriteLine($"Box: {box.Width}, {box.Height}");
  72. Console.WriteLine($"Perimeter: {box.Perimeter}");
  73. Console.WriteLine($"Area: {box.Area}");
  74. }
  75. }
  76. }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement