0% found this document useful (0 votes)
2 views4 pages

Add Item and Remove Item in Inventory

The document outlines the development of a dynamic product inventory system for an e-commerce platform using C#. It allows users to add and remove products from an ArrayList and displays the updated inventory list. The program features a menu-driven interface for user interaction.

Uploaded by

chetansharma1878
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views4 pages

Add Item and Remove Item in Inventory

The document outlines the development of a dynamic product inventory system for an e-commerce platform using C#. It allows users to add and remove products from an ArrayList and displays the updated inventory list. The program features a menu-driven interface for user interaction.

Uploaded by

chetansharma1878
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

OBJECTIVE:- You are developing a dynamic product inventory system for an e-commerce platform.

The system should allow the user to add product names to the inventory list, remove a product,
and then display the updated list of products. Since the number of products can vary, you decide
to use an ArrayList to store the product names.

Requirements:

· The program should allow the user to add new product names to an ArrayList.

· It should allow the user to remove a product by name.

Finally, the program should display the updated list of products.

CODE:-

using System;

using System.Collections;

class Program

static void Main(string[] args)

// Create an ArrayList to store product names

ArrayList productInventory = new ArrayList();

// Add some initial products to the inventory

productInventory.Add("Laptop");

productInventory.Add("Smartphone");

productInventory.Add("Headphones");

// Menu-driven loop for user interaction

bool keepRunning = true;

while (keepRunning)

Console.Clear();

Console.WriteLine("Product Inventory System");

Console.WriteLine("-------------------------");

Console.WriteLine("1. Add a new product");


Console.WriteLine("2. Remove a product by name");

Console.WriteLine("3. Display all products");

Console.WriteLine("4. Exit");

Console.Write("Please choose an option: ");

string choice = Console.ReadLine();

switch (choice)

case "1":

// Add a new product

Console.Write("Enter the name of the product to add: ");

string newProduct = Console.ReadLine();

productInventory.Add(newProduct);

Console.WriteLine($"{newProduct} has been added to the inventory.");

break;

case "2":

// Remove a product by name

Console.Write("Enter the name of the product to remove: ");

string productToRemove = Console.ReadLine();

if (productInventory.Contains(productToRemove))

productInventory.Remove(productToRemove);

Console.WriteLine($"{productToRemove} has been removed from the inventory.");

else

Console.WriteLine($"Product '{productToRemove}' not found in the inventory.");

break;
case "3":

// Display all products

Console.WriteLine("\nCurrent Product Inventory:");

foreach (var product in productInventory)

Console.WriteLine("- " + product);

break;

case "4":

// Exit the program

Console.WriteLine("Exiting the program...");

keepRunning = false;

break;

default:

Console.WriteLine("Invalid choice, please try again.");

break;

// Pause before the next operation

Console.WriteLine("\nPress any key to continue...");

Console.ReadKey();

}OUTPUT:-

Product Inventory System

-------------------------

1. Add a new product

2. Remove a product by name


3. Display all products

4. Exit

Please choose an option: 1

Enter the name of the product to add: phone

phone has been added to the inventory.

Press any key to continue...

Product Inventory System

-------------------------

1. Add a new product

2. Remove a product by name

3. Display all products

4. Exit

Please choose an option: 3

Current Product Inventory:

- Laptop

- Smartphone

- Headphones

- phone

Press any key to continue...

You might also like