In: Computer Science
$$$$$$$$$$$$$$ please write in C# $$$$$$$$$$$$$$$
Write a program to keep track of a hardware store’s inventory. You will need to create necessary classes for handling the data and a separate client class with the main method.
The store sells various items. For each item in the store, the following information is maintained: item ID, item name, number of pieces currently in the store, manufacturer’s price of the item and the store’s selling price. Create a class Item to store the information about the items. Provide appropriate setters and getters. Override the toString() method.
Create a class Inventory that contains a vector of items. This class will contain a bunch of methods to help build the application. Create a static variable to keep track of the total different items in inventory. Every time a new item is added to the inventory this variable has to be updated.
ItemID,itemName,pInstore,manufPrice,sellingPrice
ItemID itemName pInstore manufPrice sellingPrice
12 Circular saw 150 45.00 125.00
235 Cooking Range 50 450.0 850.00
.
Total Inventory: $####.##
Total number of items in the store:
The total inventory is the total selling value of all the items currently in the store. The total number of items is the sum of the number of pieces of all items in the store.
Create a separate client class with the main method, display the menu and use switch case statement to execute appropriate method. The main method should display a menu with the following choices such as:
For option 1, the user must also be prompted for the itemID. You will then call the method created in the Inventory class.
For option 2, verify if pInstore > qtyOrdered. You will invoke the method created in Inventory class.
For option 3, display the report. Again, this is nothing but executing method from Inventory class.
Also after an item is sold update the appropriate counts. Initially, the number of pieces in the store is the same as the number of pieces ordered and the number of pieces of an item sold is zero. You will use the utility method created as part of Inventory class.
Screenshot
Program
using System;
using System.Collections.Generic;
namespace InventoryInCSharp
{
//Create a class Item{
class Item
{
//Attributes
private int
itemID;
private string
itemName;
private int
plnStore;
private float
manuPrice;
private float
sellingPrice;
//constructor
public Item(int
id,string name,int cnt,float mPr,float sPr)
{
itemID = id;
itemName = name;
plnStore = cnt;
manuPrice = mPr;
sellingPrice = sPr;
}
//Getters and
setters
public int ItemId
{
set
{
itemID = value;
}
get
{
return itemID;
}
}
public string
ItemName
{
set
{
ItemName = value;
}
get
{
return itemName;
}
}
public int ItemCnt
{
set
{
this.plnStore = value;
}
get
{
return this.plnStore;
}
}
public float
ItemMPrice
{
set
{
this.manuPrice = value;
}
get
{
return this.manuPrice;
}
}
public float
ItemSPrice
{
set
{
this.sellingPrice = value;
}
get
{
return this.sellingPrice;
}
}
//To string
implementation
public override string
ToString()
{
string str = String.Format("{0,5} {1,20} {2,10} {3,15} {4,15}",
itemID, itemName, plnStore, manuPrice.ToString("#.00"),
sellingPrice.ToString("#.00"));
return str;
}
}
//Create class Inventory
class Inventory
{
//Attributes
private List<Item> items
= new List<Item>();
static int totalItems=0;
static float totalPrice =
0;
//Create an inventory of
5 items
public void
createInventory()
{
items.Add(new Item(12, "Circular saw", 150, 45, 125));
items.Add(new Item(235,"Cooking Range",50,450,850));
items.Add(new Item(15, "Screw Driver", 75,10,15));
items.Add(new Item(25, "Cooking Gadget", 100, 25, 35));
items.Add(new Item(235, "Tilter", 60,30,35));
for (int i = 0; i < items.Count; i++)
{
Inventory.totalItems += items[i].ItemCnt;
Inventory.totalPrice += items[i].ItemSPrice*
items[i].ItemCnt;
}
}
//Search an item
public void
searchItem(int id)
{
int cnt = items.Count;
for (int i = 0; i <cnt; i++)
{
if (items[i].ItemId == id)
{
Console.WriteLine("Item details are: "+items[i]);
return;
}
}
Console.WriteLine("Not found in inventory!!!");
}
//Update inventory
data
public void
updateInventory(int id,int quantityOrdered)
{
for (int i = 0; i < items.Count; i++)
{
if (items[i].ItemId == id)
{
if (items[i].ItemCnt >= quantityOrdered)
{
items[i].ItemCnt -= quantityOrdered;
Inventory.totalPrice -= (quantityOrdered* items[i].ItemCnt);
Inventory.totalItems -= quantityOrdered;
Console.WriteLine(quantityOrdered + " " + items[i].ItemName + "
sold ");
return;
}
}
}
Console.WriteLine("Item not found in the list!!");
}
//Print report
public void
printReport()
{
Console.WriteLine("\nItemID
itemName
pInstore manufPrice
sellingPrice");
for (int i = 0; i < items.Count; i++)
{
Console.WriteLine(items[i]);
}
Console.WriteLine("Total Inventory: $"+Inventory.totalPrice);
Console.WriteLine("Total number of items in the store:
"+Inventory.totalItems);
}
}
//Test class
class Program
{
static void
Main(string[] args)
{
//Inventory object
Inventory inventory = new Inventory();
//Fill inventory
inventory.createInventory();
//User choice
int opt = userMenu();
//loop until exit
while (opt != 4)
{
//Each options
switch (opt)
{
case 1:
Console.Write("\nEnter item id to search: ");
int id = Convert.ToInt32(Console.ReadLine());
inventory.searchItem(id);
break;
case 2:
Console.Write("\nEnter item id to sell: ");
id = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter quantity to sell: ");
int quant = Convert.ToInt32(Console.ReadLine());
inventory.updateInventory(id, quant);
break;
case 3:
inventory.printReport();
break;
default:
break;
}
Console.WriteLine();
//Repetition
opt = userMenu();
}
}
//Method to get user
choice without error
static int
userMenu()
{
Console.WriteLine("USER OPTIONS: ");
Console.WriteLine("1. Check whether an item is in the store\n2.
Sell an item\n3. Print the report\n4. Exit");
Console.Write("Enter your choice: ");
int opt = Convert.ToInt32(Console.ReadLine());
while(opt<1 || opt > 4)
{
Console.WriteLine("Error!!!Choice must be 1-4");
Console.Write("Enter your choice: ");
opt = Convert.ToInt32(Console.ReadLine());
}
return opt;
}
}
}
------------------------------------------------------------
Output
USER OPTIONS:
1. Check whether an item is in the store
2. Sell an item
3. Print the report
4. Exit
Enter your choice: 1
Enter item id to search: 12
Item details are:
12 Circular
saw
150
45.00
125.00
USER OPTIONS:
1. Check whether an item is in the store
2. Sell an item
3. Print the report
4. Exit
Enter your choice: 2
Enter item id to sell: 12
Enter quantity to sell: 10
10 Circular saw sold
USER OPTIONS:
1. Check whether an item is in the store
2. Sell an item
3. Print the report
4. Exit
Enter your choice: 3
ItemID
itemName
pInstore manufPrice
sellingPrice
12
Circular saw
140
45.00
125.00
235 Cooking
Range
50
450.00
850.00
15
Screw Driver
75
10.00
15.00
25 Cooking
Gadget
100
25.00
35.00
235
Tilter
60
30.00
35.00
Total Inventory: $66575
Total number of items in the store: 425
USER OPTIONS:
1. Check whether an item is in the store
2. Sell an item
3. Print the report
4. Exit
Enter your choice: 4
---------------------------------------------
Note:-
I assume you are expecting program this way.