From d6a34fd3d5cd47821e895bbea00087f8173a8434 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Qui=C3=B1anola=20CJ?= Date: Sat, 21 Feb 2026 11:39:26 +0800 Subject: [PATCH] Add files via upload --- InventoryService.cs | 54 ++++++++++++++++++++++++++ InventoryView.cs | 92 +++++++++++++++++++++++++++++++++++++++++++++ Program.cs | 13 +++++++ 3 files changed, 159 insertions(+) create mode 100644 InventoryService.cs create mode 100644 InventoryView.cs create mode 100644 Program.cs diff --git a/InventoryService.cs b/InventoryService.cs new file mode 100644 index 0000000..b9a4dcf --- /dev/null +++ b/InventoryService.cs @@ -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(); + } + } + } +} \ No newline at end of file diff --git a/InventoryView.cs b/InventoryView.cs new file mode 100644 index 0000000..ad7e36b --- /dev/null +++ b/InventoryView.cs @@ -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."); + } + } + } +} \ No newline at end of file diff --git a/Program.cs b/Program.cs new file mode 100644 index 0000000..38d61ed --- /dev/null +++ b/Program.cs @@ -0,0 +1,13 @@ +using InventoryManagement.Views; + +namespace InventoryManagement +{ + class Program + { + static void Main(string[] args) + { + InventoryView view = new InventoryView(); + view.Run(); + } + } +} \ No newline at end of file