Question

In: Computer Science

Question: In C#: For today's lab you will be creating a store inventory management system. Your...

Question: In C#: For today's lab you will be creating a store inventory management system. Your program will have to have the following elements. It should allow any number of customers to shop at the store using names to identify each one. The user should be able to select which one is the current customer. The system must contain a list of at least 50 items (repeats are allowed) that can be purchased by the customers. For a customer to make a purchase they must transfer the items they wish to buy to their own shopping cart. (A Shopping cart list should be maintained for each customer). The user should be able to switch between customers without losing the contents of each customer's cart. The user can select complete purchase and will be presented with a total for that user’s purchases. Customers should be able to remove items from their cart and return them to the stores inventory. A customer’s cart should be removed after her/his purchase is complete. NOTE: The code structure and guidelines are light because this exercise is designed to test your critical thinking skills and see how you apply the skills you’ve learned throughout the duration of this class.

Use the following guidelines to complete this application:

Classes

Classes should be used to represent Inventory Items

Customers

List(s)

Lists should be used to represent The stores inventory Customers shopping carts

Dictionary

A Dictionary should be used to Track all of the customers - identified by their name

User Options

The user should have the following options:

Select current shopper - list of all shoppers and option to create another shopper

View store inventory - list everything the store is selling

View cart - list of everything in the current Customers cart

Add item to cart - allow the user to select an item to add to the current Customer’s cart and remove it from the store’s inventory. (Can be combined with the View store option if you wish) Remove item from cart - allow the user to select an item to add to the stores inventory and remove it from the current Customer’s cart. (can be combined with the View cart option if you wish)

Complete purchase - Total up the cost of all of the items in the user’s cart and display that value. Remove the customer from the dictionary of customers

Exit - Exit the program

Input

All input should be validated and limited to the options presented to the user The user should not be able to crash the program Program should continue to run until the user chooses to exit File IO

Generate a "receipt" for the customer when they purchase their items.

The receipt contains: Customer name Time of transaction List of items purchased (name & cost) Total cost of items Feel free to add a sub-total and tax (not required). A new receipt file is generated for each completed purchase. Do not overwrite or append to a previous file. The file name: Indicates which customer completed the purchase. What order the receipts were generated. There is more than one good solution to this requirement, do not seek help for this feature - use critical thinking.

Solutions

Expert Solution

CODE:

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ShopperCart
{
// Inventory class
class Inventory
{
public string Name { get; set; }
public double Price { get; set; }

}
// Customer Class
class Customer
{
public string Name { get; set; }
public List<Inventory> Cart { get; set; }
}
class Program
{
// global scoped inventory collection
private static Dictionary<string, Inventory> _inventoryCol;
// global scoped customer collection
private static Dictionary<string, Customer> _customerCol;
static void Main(string[] args)
{
// intialise the customer collection
_customerCol = new Dictionary<string, Customer>();
// load inventory collection
LoadInventory();
// start of the menu
// take name to add to our system
Console.WriteLine("Please enter the customer name add or switch to your collection");
string tempName = Console.ReadLine().Trim();

// add name and make it acrive customer
string activeCutomer=AddCustomer(tempName);
// menu loop
while (true)
{
//Display the inventory list
ShowInventory();
Console.WriteLine("Please enter the Inventory name to add to your collection");
string tempInven = Console.ReadLine().Trim();
// add selected inventory item to customer cart
AddInventoryToCustomer(_customerCol[activeCutomer],tempInven);

// Menu to ask user to see the cart
Console.WriteLine("Type Yes to view Cart, nothing to continue");
string viewCart = Console.ReadLine().Trim();
if (viewCart.ToLower() == "yes")
ViewCurrentCustCart(activeCutomer);

// Menu to ask user to generate the receipt
Console.WriteLine("Type Yes to generate script, nothing to continue");
string genReceipt = Console.ReadLine().Trim();
if(genReceipt.ToLower()=="yes")
GenerateReceipt(activeCutomer);

// Menu to ask user to remove particular customer
Console.WriteLine("Want to remove any customer from the customer list?, Type name to remove, nothing to continue");
string deleteName = Console.ReadLine().Trim();
if (!string.IsNullOrEmpty(deleteName))
RemoveFromCustomerCollection(deleteName);

// Menu to ask user to exit the menu
Console.WriteLine("Press X to exit, any other key to continue adding item to cart");
string exitKey = Console.ReadLine().Trim();
if (exitKey.ToLower() == "x")
break;
  
}
}

// removes user from the customer collection
private static void RemoveFromCustomerCollection(string deleteName)
{
if (_customerCol.ContainsKey(deleteName))
{
_customerCol.Remove(deleteName);
Console.WriteLine("Successfully removed Customer: {0} from our system",deleteName);
}
else
{
Console.WriteLine("Supplied Customer to remove is not in our system");
}
}

// generate script based on the cart items and names it to the cutomer Receipt CustomerName_currentDateTime.txt
private static void GenerateReceipt(string activeCutomer)
{
// check the presence
if (_customerCol[activeCutomer].Cart.Count > 0)
{
string content = string.Format("Name : {0}{1}", activeCutomer, Environment.NewLine);
content+= string.Format("Name\t\tPrice{0}",Environment.NewLine);
double total=0;
foreach (Inventory item in _customerCol[activeCutomer].Cart)
{
total += item.Price;
content += string.Format("{0}\t\t{1}{2}", item.Name, item.Price, Environment.NewLine);
}
content += string.Format("Total\t\t{0}", total);
string path = string.Format("Receipt_{0}_{1}.txt", activeCutomer, DateTime.Now.ToLongDateString());
File.WriteAllText(path, content);
// write to text file
Console.WriteLine("Receipt with name : {0} generated succesfully.", path);
}
  
}

// view the current status of Cart for active customer
private static void ViewCurrentCustCart(string activeCutomer)
{
if (_customerCol[activeCutomer].Cart.Count > 0)
{
Console.WriteLine("Name\t\tPrice");
foreach (Inventory item in _customerCol[activeCutomer].Cart)
{
Console.WriteLine("{0}\t\t{1}", item.Name, item.Price);
}
}
}

// Add inventory item to the active customer's cart
private static void AddInventoryToCustomer(Customer customer, string tempInven)
{
if (_inventoryCol.ContainsKey(tempInven))
{
customer.Cart.Add(_inventoryCol[tempInven]);
}
else
{
Console.WriteLine("Provided Inventory Item: {} is not present in our system, please try again");
}
}


// Add customer to our customer collection
private static string AddCustomer(string name)
{
if(_customerCol.ContainsKey(name))
{
Console.WriteLine("Customer is already in our system, we are making it active.");
return name;
}
else
{
Console.WriteLine("Customer is new to our system, we are adding it and making it active.");
_customerCol.Add(name, new Customer() { Name = name, Cart = new List<Inventory>() });
return name;
}
}

// system initiated inventory loader
private static void LoadInventory()
{
List<string> items = new List<string>() {"Phone","Battery","Laptop","Book","Mouse","Wallet","Item1","bottle","paper","can","itemx","item t"};
Random rand = new Random();
_inventoryCol = new Dictionary<string, Inventory>();
foreach (string item in items)
{
_inventoryCol.Add(item, new Inventory() { Name = item, Price =rand.Next(100,12345)});
}
  
}

// display the inventory list
private static void ShowInventory()
{

if (_inventoryCol.Count > 0)
{
Console.WriteLine("Name\t\tPrice");
foreach (KeyValuePair<string,Inventory> item in _inventoryCol)
{
Console.WriteLine("{0}\t\t{1}", item.Value.Name, item.Value.Price);
}
}
}
}
}

RESULT:

Receipt:

Name : Alex
Name       Price
Wallet       8335
bottle       6137
can       8112
Total       22584


Related Solutions

Question 1: Using a computerized Inventory Management System, a Paint Supply Store franchise continuously monitors the...
Question 1: Using a computerized Inventory Management System, a Paint Supply Store franchise continuously monitors the inventory of all the paint located at each of their 15 stores and their distribution warehouse. The Paint Supply Store franchise sells an average of 32 gallons of Red Paint every week (for 52 weeks per year, Standard Deviation of the Demand = 4 gallons). They purchase Red Paint from their supplier at a price of $2.00 per gallon. It takes 1.25 weeks to...
Java code for creating an Inventory Management System of any company - designing the data structure(stack,...
Java code for creating an Inventory Management System of any company - designing the data structure(stack, queue, list, sort list, array, array list or linked list) (be flexible for future company growth Java code for creating an initial list in a structure. Use Array (or ArrayList) or Linkedlist structure whichever you are confident to use. - Implement Stack, Queue, List type structure and proper operation for your application. Do not use any database. All data must use your data structures....
In this Question using c++, you are to develop an employee management system using classes. You...
In this Question using c++, you are to develop an employee management system using classes. You need to develop two classes: Date and Employee. The Date class has the three attributes (int): month, day, and year. The class has the following member functions: • string getDate(void): returns a string with the date information (e.g, Mach 27, 2020). In addition to these, declare and implement proper constructors, a copy constructor, a destructor, and getters and setters for all data members. The...
In C++ In this lab we will be creating a stack class and a queue class,...
In C++ In this lab we will be creating a stack class and a queue class, both with a hybrid method combining linked list and arrays in addition to the Stack methods(push, pop, peek, isEmpty, size, print) and Queue methods (enqueue, deque, peek, isEmpty, size, print). DO NOT USE ANY LIBRARY, implement each method from scratch. Both the Stack and Queue classes should be generic classes. Don't forget to comment your code.
what do you understand by a) inventory management b) materials management c) inventory control
what do you understand by a) inventory management b) materials management c) inventory control
In C++ In this lab we will creating two linked list classes: one that is a...
In C++ In this lab we will creating two linked list classes: one that is a singly linked list, and another that is a doubly linked list ( This will be good practice for your next homework assignment where you will build your own string class using arrays and linked list ) . These LinkedList classes should both be generic classes. and should contain the following methods: Print Add - Adds element to the end of the linked list. IsEmpty...
have you considered the risks in creating your management team? Explain.
have you considered the risks in creating your management team? Explain.
Assignment Question Operations Management for creating a Competitive Advantage for an organization of your choice, write...
Assignment Question Operations Management for creating a Competitive Advantage for an organization of your choice, write a report in which you carry out the following: Overview         Discuss and apply any relevant operations management strategies and theories that you identify for this organization.        Comment on the quality of the organization’s output and its strategic fit with its current operations processes and systems in the design and delivery of its product.        Recommend the most appropriate and...
In this assignment you are to make an inventory management system for a car dealership. The...
In this assignment you are to make an inventory management system for a car dealership. The dealerships current method of tracking inventory is using a list which has the color and name of each car they have in inventory. There current inventory list will look like the example below. RED TOYOTAWHITE HONDA...BLACK BMW The types of cars that they order are as follows: TOYOTA, HONDA, BMW, NISSAN, TESLA, DODGE The colors they purchase are as follows: RED, WHITE, BLUE, BLACK,...
In C++ please: In this lab we will creating two linked list classes: one that is...
In C++ please: In this lab we will creating two linked list classes: one that is a singly linked list, and another that is a doubly linked list ( This will be good practice for your next homework assignment where you will build your own string class using arrays and linked list ) . These LinkedList classes should both be generic classes. and should contain the following methods: Print Add - Adds element to the end of the linked list....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT