Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace Problem
- {
- class Program
- {
- static void Main(string[] args)
- {
- Warehouse warehouse = new Warehouse();
- warehouse.ShowInventory();
- }
- }
- class Warehouse
- {
- static readonly Random random = new Random();
- private List<Slot> inventory;
- public Warehouse()
- {
- FillInventory();
- }
- private void FillInventory()
- {
- List<Detail> tempList = DetailInstance.CopyDetails();
- inventory = new List<Slot>();
- for (int i = 0; i < tempList.Count; i++)
- {
- inventory.Add(new Slot(tempList[i], random.Next(5)));
- }
- }
- internal void ShowInventory()
- {
- foreach (var item in inventory)
- {
- Console.WriteLine(item);
- }
- }
- }
- class Slot
- {
- public Slot(Detail detail, int count)
- {
- Detail = detail;
- Count = count;
- }
- public Detail Detail { get; private set; }
- public int Count { get; private set; }
- public override string ToString()
- {
- return $"{Detail.Name} ${Detail.Price} - Count: {Count}";
- }
- }
- class DetailInstance
- {
- private static readonly List<Detail> details = new List<Detail>()
- {
- new Detail(),
- new Detail(),
- new Detail(),
- new Detail(),
- new Detail(),
- new Detail(),
- new Detail()
- };
- public static List<Detail> CopyDetails() => details.ToList();
- }
- class Detail
- {
- public Detail()
- {
- Name = "Гайка";
- Price = 20;
- }
- public string Name { get; private set; }
- public int Price { get; private set; }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement