Belgia 251 PRG PRAC
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Project_2._1
{
internal class AntiStatic
{
#region Fields
private string[,] array = new string[100, 3];
private int counter = 2;
#endregion Fields
#region Enums
private enum Menu
{
Add_Items = 1,
SearchForItems,
DisplayAllItems,
Exit
}
#endregion Enums
#region Methods
private int Actions(int choosen)
{
Menu MenuChoice = new Menu(); MenuChoice = (Menu)choosen;
switch (MenuChoice)
{
case Menu.Add_Items:
return 1;
break;
case Menu.SearchForItems:
return 2;
break;
case Menu.DisplayAllItems:
return 3;
break;
case Menu.Exit:
return 4;
break;
default:
return 5;
break;
}
}
private void add_items()
{
counter += 1;
Console.WriteLine("Item Name");
array[counter, 0] = Console.ReadLine();
Console.WriteLine("Item Model");
array[counter, 1] = Console.ReadLine();
Console.WriteLine("Price of Item");
array[counter, 2] = Console.ReadLine();
}
private void displayAll()
{
Array obj = array;
for (int i = counter; i > -1; i--)
{
Console.WriteLine(array[i, 0] + " " + array[i, 1] + " " + array[i, 2]);
}
Console.WriteLine("\n\nPress a key to continue");
Console.ReadLine();
}
private void searcheck()
{
Console.WriteLine("Model?");
string a = Console.ReadLine();
for (int i = counter; i > -1; i--)
{
if (array[i, 1] == a) { Console.WriteLine(array[i, 0] + " " + array[i, 1] + " " + array[i, 2]); }
}
Console.WriteLine("Press a key to continue");
Console.ReadKey();
}
public void additems()
{
array[0, 0] = "Huawei";
array[0, 1] = "2021";
array[0, 2] = "1500";
array[1, 0] = "Mara";
array[1, 1] = "2019";
array[1, 2] = "1000";
array[2, 0] = "Samsung";
array[2, 1] = "2020";
array[2, 2] = "900";
}
public void menuDoisplay()
{
Console.Clear();
Console.WriteLine("1. Add items\n2. Search For Items\n3. Display All items\n.4 Exit");
}
public void MenuLoop()
{
int operations = 5;
do
{
menuDoisplay();
try
{
operations = Actions(int.Parse(Console.ReadLine()));
if (operations != 5)
{
if (operations == 4)
{
break;
}
if (operations == 1)
{
add_items();
}
if (operations == 2)
{
searcheck();
}
if (operations == 3)
{
displayAll();
}
}
}
catch (Exception e)
{
//Console.WriteLine(e);
//Console.ReadLine();
}
} while (operations != 4);
}
#endregion Methods
}
}
White Lord