Skip to content
This repository was archived by the owner on Feb 21, 2026. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions InventoryService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
namespace InventoryManagement.Services
{
public class InventoryService
{
private string[,] products;
private int[] initialStock;

public InventoryService()
{
products = new string[2, 3];

// Row 0 - Product Names
products[0, 0] = "Apples";
products[0, 1] = "Milk";
products[0, 2] = "Bread";

// Row 1 - Stock Quantities
products[1, 0] = "10";
products[1, 1] = "5";
products[1, 2] = "20";

// Store original stock values
initialStock = new int[3];
for (int i = 0; i < 3; i++)
{
initialStock[i] = int.Parse(products[1, i]);
}
}

// Return inventory array
public string[,] GetInventory()
{
return products;
}

// Update stock for a product
public void UpdateStock(int productIndex, int newStock)
{
if (productIndex >= 0 && productIndex < 3)
{
products[1, productIndex] = newStock.ToString();
}
}

// Reset inventory to original stock
public void ResetInventory()
{
for (int i = 0; i < 3; i++)
{
products[1, i] = initialStock[i].ToString();
}
}
}
}
92 changes: 92 additions & 0 deletions InventoryView.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
using System;
using InventoryManagement.Services;

namespace InventoryManagement.Views
{
public class InventoryView
{
private InventoryService service;

public InventoryView()
{
service = new InventoryService();
}

public void Run()
{
bool isRunning = true;

while (isRunning)
{
Console.WriteLine("\n===== Inventory Management System =====");
Console.WriteLine("1. View Inventory");
Console.WriteLine("2. Update Stock");
Console.WriteLine("3. Reset Inventory");
Console.WriteLine("4. Exit");
Console.Write("Select an option: ");

string choice = Console.ReadLine();

switch (choice)
{
case "1":
DisplayInventory();
break;

case "2":
UpdateStock();
break;

case "3":
service.ResetInventory();
Console.WriteLine("Inventory has been reset to original values.");
break;

case "4":
isRunning = false;
Console.WriteLine("Exiting program...");
break;

default:
Console.WriteLine("Invalid option. Please try again.");
break;
}
}
}

private void DisplayInventory()
{
string[,] products = service.GetInventory();

Console.WriteLine("\nCurrent Inventory:");
for (int i = 0; i < products.GetLength(1); i++)
{
Console.WriteLine($"{i + 1}. {products[0, i]} - Stock: {products[1, i]}");
}
}

private void UpdateStock()
{
DisplayInventory();

Console.Write("Select product number to update: ");
if (int.TryParse(Console.ReadLine(), out int productChoice))
{
Console.Write("Enter new stock quantity: ");
if (int.TryParse(Console.ReadLine(), out int newStock))
{
service.UpdateStock(productChoice - 1, newStock);
Console.WriteLine("Stock updated successfully.");
}
else
{
Console.WriteLine("Invalid stock value.");
}
}
else
{
Console.WriteLine("Invalid selection.");
}
}
}
}
13 changes: 13 additions & 0 deletions Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using InventoryManagement.Views;

namespace InventoryManagement
{
class Program
{
static void Main(string[] args)
{
InventoryView view = new InventoryView();
view.Run();
}
}
}