Advertisement
2629881

Untitled

Jul 30th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.24 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 inventory
  8. {
  9.     using System;
  10. using System.Collections.Generic;
  11. using System.Linq;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14.  
  15. namespace inventory
  16. {
  17.     public class Inventory
  18.     {
  19.         string[] arrayItems = new string[6];        
  20.          
  21.         public void AddItem(string item)
  22.         {
  23.             for (int i = 0; i < arrayItems.Length; i++)
  24.             {
  25.                 if (arrayItems[i] == null)
  26.                 {
  27.                     arrayItems[i] = item;
  28.                     return;
  29.                 }
  30.             }
  31.             Console.WriteLine("{0} has been added to your inventory", item);
  32.         }
  33.  
  34.         public void DisplayItems()
  35.         {
  36.             Console.WriteLine("Your items are:");
  37.             foreach (string item in arrayItems)
  38.             {
  39.                 Console.Write(item + ";");
  40.             }
  41.             Console.WriteLine();
  42.         }
  43.     }
  44. }
  45.  
  46.     class Program
  47.     {
  48.         static void Main(string[] args)
  49.         {
  50.             Inventory inventory = new Inventory();
  51.             //Console.WriteLine("Wpisz komende /add /switch /display.");
  52.             //Console.WriteLine();
  53.             // test
  54.             inventory.DisplayItems();
  55.             //Console.WriteLine();
  56.             inventory.AddItem("DUPA");
  57.             inventory.AddItem("BISKUPA");
  58.             //Console.WriteLine();
  59.             inventory.DisplayItems();
  60.             // test
  61.  
  62.  
  63.  
  64.             //while (true)
  65.             //{
  66.             //    string command = Console.ReadLine();
  67.             //    switch (command)
  68.             //    {
  69.             //        case "/display":
  70.             //                inventory.DisplayItems();
  71.             //                Console.WriteLine();
  72.             //            break;
  73.             //        case "/add":
  74.             //                string item = Console.ReadLine(); ;
  75.             //                inventory.AddItem(item);                
  76.             //            break;
  77.             //        case "/switch":
  78.             //            break;
  79.             //    }
  80.             //}
  81.             Console.ReadKey();
  82.         }
  83.     }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement