-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
104 lines (96 loc) · 3.25 KB
/
Program.cs
File metadata and controls
104 lines (96 loc) · 3.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
using System;
using System.Collections.Generic;
class InventoryManagementSystem
{
static List<string> inventory = new List<string>();
// false representing pinning tasks and true representing completed tasks.
static List<bool> availability = new List<bool>();
static void Main(string[] args)
{
while (true)
{
Console.WriteLine("Inventory Management System");
Console.WriteLine("1. Add Item");
Console.WriteLine("2. Remove Item");
Console.WriteLine("3. View Inventory");
Console.WriteLine("4. Update Availability");
Console.WriteLine("5. Exit");
Console.Write("Choose an option: ");
string choice = Console.ReadLine();
switch (choice)
{
case "1":
AddItem();
break;
case "2":
RemoveItem();
break;
case "3":
ViewInventory();
break;
case "4":
UpdateAvailability();
break;
case "5":
return;
default:
Console.WriteLine("Invalid option. Please try again.");
break;
}
}
}
// Method to add new product to inventory
static void AddItem()
{
Console.Write("Enter item name: ");
string name = Console.ReadLine();
Console.Write("Enter item price: ");
double price = double.Parse(Console.ReadLine());
Console.Write("Enter item quantity: ");
int quantity = int.Parse(Console.ReadLine());
inventory.Add($"{name} - Price: {price} - Quantity: {quantity}");
availability.Add(true); // Item is available
Console.WriteLine("Item added successfully.");
}
// Method to remove product from inventory
static void RemoveItem()
{
Console.Write("Enter the item name to remove: ");
string name = Console.ReadLine();
for (int i = 0; i < inventory.Count; i++)
{
if (inventory[i].StartsWith(name))
{
inventory.RemoveAt(i);
availability.RemoveAt(i);
Console.WriteLine("Item removed successfully.");
return;
}
}
Console.WriteLine("Item not found.");
}
// Method to view current inventory
static void ViewInventory()
{
for (int i = 0; i < inventory.Count; i++)
{
string status = availability[i] ? "Available" : "Out of Stock";
Console.WriteLine($"{i + 1}. {inventory[i]} - Status: {status}");
}
}
// Method to update item availability
static void UpdateAvailability()
{
Console.Write("Enter the item number to update availability: ");
int itemNumber = int.Parse(Console.ReadLine());
if (itemNumber > 0 && itemNumber <= availability.Count)
{
availability[itemNumber - 1] = !availability[itemNumber - 1];
Console.WriteLine("Item availability updated successfully.");
}
else
{
Console.WriteLine("Invalid item number.");
}
}
}