Guest User

Untitled

a guest
May 23rd, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.90 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace RainForest {
  5. class Program {
  6. static void Main (string[] args) {
  7. Company rainforest = new Company ("Rainforest, LLC");
  8.  
  9. string[] cities = new string[] { "Austin", "Houston", "Dallas", "San Antonio" };
  10. string[] items = new string[] { "Banana", "Toothpaste", "Baseball", "Laptop" };
  11.  
  12. foreach (var city in cities) {
  13. rainforest.warehouses.Add (new Warehouse (city, 1));
  14. rainforest.warehouses.Add (new Warehouse (city, 2));
  15. }
  16.  
  17. for (int i = 0; i < rainforest.warehouses.Count; i++) {
  18. Warehouse warehouse = rainforest.warehouses[i];
  19. Container container = new Container ($"{warehouse.location}-1", i + 1);
  20. rainforest.warehouses[i].containers.Add (container);
  21. }
  22.  
  23. for (int i = 0; i < 4; i++) {
  24. Container container = rainforest.warehouses[i].containers[0];
  25. Item item = new Item (items[i], i);
  26. container.items.Add (item);
  27. }
  28.  
  29. rainforest.GenerateManifest ();
  30.  
  31. Console.WriteLine ("Hello World!");
  32. }
  33. }
  34.  
  35. class Company {
  36. public string name;
  37. public List<Warehouse> warehouses;
  38.  
  39. public Company (string name) {
  40. this.name = name;
  41. this.warehouses = new List<Warehouse> ();
  42. }
  43.  
  44. public void GenerateManifest () {
  45. string html = @"
  46. <html>
  47. <head>
  48. <style>
  49. .company, .warehouse, .container, .item {
  50. padding: 20px;
  51. display: flex;
  52. margin: 10px;
  53. flex-wrap: wrap;
  54. }
  55. .warehouse {
  56. background-color: lightsteelblue;
  57. }
  58. .container {
  59. background-color: lightgreen;
  60. }
  61. .item {
  62. background-color: lightpink;
  63. }
  64. </style>
  65. </head>
  66. <body>
  67. ";
  68. html += String.Format (@"
  69. <h1>{0}</h1>
  70. <div class='company'>
  71. ", this.name);
  72.  
  73. foreach (var warehouse in this.warehouses) {
  74. html += String.Format ("<div class=\"warehouse\">{0}", warehouse.location);
  75. foreach (var container in warehouse.containers) {
  76. html += String.Format ("<div class=\"container\">{0}", container.id);
  77. foreach (var item in container.items) {
  78. html += String.Format ("<div class=\"item\">{0}</div>", item.name);
  79. }
  80. html += "</div>";
  81. }
  82. html += "</div>";
  83. }
  84. html += "</div>";
  85. html += "</html>";
  86.  
  87. System.IO.File.WriteAllText (@"./index.html", html);
  88. }
  89. }
  90.  
  91. class Warehouse {
  92. public string location;
  93. public int size;
  94. public List<Container> containers;
  95.  
  96. public Warehouse (string location, int size) {
  97. this.location = location;
  98. this.size = size;
  99. this.containers = new List<Container> ();
  100. }
  101.  
  102. }
  103.  
  104. class Container {
  105. public List<Item> items;
  106. public int size;
  107. public string id;
  108.  
  109. public Container (string id, int size) {
  110. this.id = id;
  111. this.size = size;
  112. this.items = new List<Item> ();
  113. }
  114.  
  115. }
  116.  
  117. class Item {
  118. public string name;
  119. public double price;
  120.  
  121. public Item (string name, double price) {
  122. this.name = name;
  123. this.price = price;
  124. }
  125.  
  126. }
  127. }
Add Comment
Please, Sign In to add comment