Advertisement
GigaOrts

Untitled

Jun 14th, 2023
755
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.00 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Problem
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             Warehouse warehouse = new Warehouse();
  12.             warehouse.ShowInventory();
  13.         }
  14.     }
  15.  
  16.     class Warehouse
  17.     {
  18.         static readonly Random random = new Random();
  19.         private List<Slot> inventory;
  20.  
  21.         public Warehouse()
  22.         {
  23.             FillInventory();
  24.         }
  25.  
  26.         private void FillInventory()
  27.         {
  28.             List<Detail> tempList = DetailInstance.CopyDetails();
  29.             inventory = new List<Slot>();
  30.  
  31.             for (int i = 0; i < tempList.Count; i++)
  32.             {
  33.                 inventory.Add(new Slot(tempList[i], random.Next(5)));
  34.             }
  35.         }
  36.  
  37.         internal void ShowInventory()
  38.         {
  39.             foreach (var item in inventory)
  40.             {
  41.                 Console.WriteLine(item);
  42.             }
  43.         }
  44.     }
  45.  
  46.     class Slot
  47.     {
  48.         public Slot(Detail detail, int count)
  49.         {
  50.             Detail = detail;
  51.             Count = count;
  52.         }
  53.  
  54.         public Detail Detail { get; private set; }
  55.         public int Count { get; private set; }
  56.  
  57.         public override string ToString()
  58.         {
  59.             return $"{Detail.Name} ${Detail.Price} - Count: {Count}";
  60.         }
  61.     }
  62.  
  63.     class DetailInstance
  64.     {
  65.         private static readonly List<Detail> details = new List<Detail>()
  66.         {
  67.             new Detail(),
  68.             new Detail(),
  69.             new Detail(),
  70.             new Detail(),
  71.             new Detail(),
  72.             new Detail(),
  73.             new Detail()
  74.         };
  75.  
  76.         public static List<Detail> CopyDetails() => details.ToList();
  77.     }
  78.  
  79.     class Detail
  80.     {
  81.         public Detail()
  82.         {
  83.             Name = "Гайка";
  84.             Price = 20;
  85.         }
  86.  
  87.         public string Name { get; private set; }
  88.         public int Price { get; private set; }
  89.     }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement