Question

C# question In this project, you will create your own on-line shopping store in the console...

C# question

In this project, you will create your own on-line shopping store in the console application. You can choose different products to sell in your store (at least 8 products). You will create an product inventory text file.


The program will display two options at the beginning of the program, Customer and Manager.
Customer:
If this is a new customer, the program will let customer to register with their information and assign a unique ID number to the new customer.
The customer will enter the customer id every time when they are shopping in your store and the program will keep tracking the total amount the customer spend each time to determine the discount level. You can create your discount level rule.


The program has to keep tracking the products inventory. If customer select the product that is out of stock, the program has to display a warning message and let customer continue to shop. After customer finish selecting the products, the program will calculate the subtotal, apply the discount, calculate the tax, and the total. The program will display a receipt on the screen and save it to a text file with customer information.


Manager:
   The manager option has to be password protected. The program will give the manager two option:
Display the inventory: display all the products stock information
Restock the products: add more stock for each product

You have to create different classes and utilize the inheritance features. You have to text files to keep all the information the program need. You can check some on-line store to get some ideas (Amazon, Walmart …). Make sure your program does not end unexpectedly and let user have the option to continue.   

0 0
Add a comment Improve this question Transcribed image text
Answer #1

CODE:

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

namespace EShopping
{
class Program
{
private static List<Product> _prdctList;
private const string _customerFlder= @"C:\Projects\Repos\Research\CSharp_1104_1\";
private const double _10PrcntDiscount = 1800.00;
private const string _mgrPass = "Manager1234";
static void Main(string[] args)
{
LoadProductList();
Console.WriteLine("------------------- MENU -----------------");
Console.WriteLine("Please select your role:{0}1 for CUSTOMER{1}2 for MANAGER{2}0 to EXIT",
Environment.NewLine,Environment.NewLine,Environment.NewLine);
try
{
while (true)
{
int selection = Convert.ToInt16(Console.ReadLine());
if (selection == 1)
{
CustomerMenu();
}
else if (selection == 2)
{
ManagerMenu();
}
else if (selection == 0)
{
break;
}
else
{
Console.WriteLine("Please select options from 1,2 and 0 only");
}
}
}catch(Exception ex)
{
Console.WriteLine("Invalid inputs provided, Program will exit now");
}

Console.ReadLine();
  
}

private static void ManagerMenu()
{
Console.WriteLine("----WELCOME TO MANAGER MENU-----");
try
{
Console.WriteLine("Please enter your password");
string pass = Console.ReadLine();
if (pass == _mgrPass)
{
while (true)
{
Console.WriteLine("Please select your task:{0}1 for DISPLAY INVENTORY{1}2 for ReSTOCK INVENTORY",
Environment.NewLine, Environment.NewLine);
int selection = Convert.ToInt16(Console.ReadLine());
if (selection == 1)
{
ProductMenu();
}
else if (selection == 2)
{
LoadProductList();
ProductMenu();
}
}
}
else
{
Console.WriteLine("Please enter correct password");
}
}
catch (Exception)
{
throw;
}
}

private static void CustomerMenu()
{
Console.WriteLine("----WELCOME TO CUSTOMER SECTION-----");
try
{
Console.WriteLine("Please provide the customer ID: ");
int id=Convert.ToInt32(Console.ReadLine());
Customer cstmer = new Customer();
List<string> files = Directory.GetFiles(_customerFlder).ToList();
bool fileExists = files.Any(x => x.ToLower().Contains(id.ToString()));

if (fileExists)
{
cstmer.IsNew = false;
string fileName = files.Select(x => x.ToLower().Contains(id.ToString()))
.FirstOrDefault().ToString();
List<string> lines = File.ReadAllLines(fileName).ToList();
cstmer.Name = lines[1].Trim();
Console.WriteLine("Welcome Back, {}", cstmer.Name);
}else
{
cstmer.IsNew = true;
cstmer.ID = id;
Console.WriteLine("Welcome to our portal, it seems you are visiting us for first time");
Console.WriteLine("Please enter your name:");
string name = Console.ReadLine();
cstmer.Name = name;
}
string cartList =string.Format("Customer Name:{0}{1}{2} Name\t\tQuantity",
Environment.NewLine,cstmer.Name,Environment.NewLine);
while (true)
{
ProductMenu();
Console.WriteLine("Press 1 to continue shopping, 0 to exit");
int selection = Convert.ToInt16(Console.ReadLine());
if (selection == 0)
{
break;
}
else if (selection == 1)
{}
else
{
Console.WriteLine("Please select options from 1 and 0 only");
}
  
Console.WriteLine(@"Please enter the Product Number,Quantity to add in your cart.
Example: 3,5 means 5 quantities of Product_Three");
string input = Console.ReadLine();
int[] usrInpt = input.Split(',').Select(Int32.Parse).ToArray();
if (usrInpt.Count() > 1)
{
if (_prdctList[usrInpt[0] - 1].StockQty < usrInpt[1])
Console.WriteLine("The number of selected quantity is less than that of stock of that item!");
else
{
cstmer.CartAmt+=usrInpt[1] * _prdctList[usrInpt[0] - 1].StockQty;
_prdctList[usrInpt[0] - 1].StockQty -= usrInpt[1];
cartList += string.Format("{0}{1}\t{2}", Environment.NewLine, _prdctList[usrInpt[0] - 1].PrdctName, usrInpt[0]);
}
}
}

double amt = cstmer.CartAmt > _10PrcntDiscount ? cstmer.CartAmt * 0.9 : cstmer.CartAmt;
string custFileName = string.Format("{0}CUSTOMER_{1}.txt", _customerFlder, id);
string receiptFileName = string.Format("{0}CUSTOMER_{1}_{2}.txt", _customerFlder, id,DateTime.Now.ToString("ddMMyyyy_hhmm"));
cartList += string.Format("\n{0}Total Amount: {1}", Environment.NewLine,amt);
if (cstmer.IsNew)
{
string newFile = string.Format("CUSOMER{0}{1}{2}", Environment.NewLine, cstmer.Name, Environment.NewLine);
newFile += string.Format("{0}Shopping on {1} for total sum of: {2}",Environment.NewLine,DateTime.Now.ToShortDateString(),amt);
File.WriteAllText(custFileName, newFile);
}
else
{
string cntent= string.Format("{0}Shopping on {1} for total sum of: {2}", Environment.NewLine, DateTime.Now.ToString("ddMMyyyy_hhmm"), amt);
File.AppendAllText(custFileName, cntent);
}

// Gnenerate Script
File.WriteAllText(receiptFileName, cartList);

}
catch(Exception ex)
{
throw;
}
}

private static void LoadProductList()
{
_prdctList = new List<Product>();
Random rand = new Random();
_prdctList.Add(new Product() { PrdctName = "Product_One", StockQty = rand.Next(6, 15), PricePerUnit = rand.Next(120, 5678) });
_prdctList.Add(new Product() { PrdctName = "Product_Two", StockQty = rand.Next(6, 15), PricePerUnit = rand.Next(120, 5678) });
_prdctList.Add(new Product() { PrdctName = "Product_Three", StockQty = rand.Next(6, 15), PricePerUnit = rand.Next(120, 5678) });
_prdctList.Add(new Product() { PrdctName = "Product_Four", StockQty = rand.Next(6, 15), PricePerUnit = rand.Next(120, 5678) });
_prdctList.Add(new Product() { PrdctName = "Product_Five", StockQty = rand.Next(6, 15), PricePerUnit = rand.Next(120, 5678) });
_prdctList.Add(new Product() { PrdctName = "Product_Six", StockQty = rand.Next(6, 15), PricePerUnit = rand.Next(120, 5678) });
_prdctList.Add(new Product() { PrdctName = "Product_Seven", StockQty = rand.Next(6, 15), PricePerUnit = rand.Next(120, 5678) });
_prdctList.Add(new Product() { PrdctName = "Product_Eight", StockQty = rand.Next(6, 15), PricePerUnit = rand.Next(120, 5678) });
}

private static void ProductMenu()
{
Console.WriteLine("Item:\t\tStock Quantity");
int cntr = 1;
foreach (Product item in _prdctList)
{
Console.WriteLine("{0} {1}\t{2}",cntr,item.PrdctName,item.StockQty);
cntr++;
}
}
}

class Product
{
public string PrdctName { get; set; }
public int StockQty { get; set; }

public double PricePerUnit { get; set; }
}

class Person
{
public string Name { get; set; }
}

class Customer : Person
{
public Int32 ID { get; set; }
public bool IsNew { get; set; }
public double CartAmt { get; set; }
}

}

RESULT:

INVOICE:

Customer Name:
Smith John
Name Quantity
Product_Four 4
Product_Three 3
Product_Five 5
Product_Eight 8
Product_Two 2
Product_One 1
Product_Eight 8

Total Amount: 311

Add a comment
Know the answer?
Add Answer to:
C# question In this project, you will create your own on-line shopping store in the console...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • This assignment requires the development of C++ software that supports order processing, account ...

    This assignment requires the development of C++ software that supports order processing, account management, and inventory control activities of an imaginary food service. Assume that customers of this food service will use a separate Web-based app (not included in this assignment) to browse product catalogs and then create shopping lists stored in specially formatted text files (see input definitions below). Each shopping list may include: Food item names and quantity. Coupon information that includes the name of the food and...

  • Please solve using c++ plus There are two text files with the following information stored in...

    Please solve using c++ plus There are two text files with the following information stored in them: The instructor.txt file where each line stores the id, name and affiliated department of an instructor separated by a comma The department.txt file where each line stores the name, location and budget of the department separated by a comma You need to write a C++ program that reads these text files and provides user with the following menu: 1. Enter the instructor ID...

  • This is extra information about the shopping database given to answer this question: For many query...

    This is extra information about the shopping database given to answer this question: For many query questions we refer to the following database schema for a website that keeps track of what people like to buy or actually buy in different on-line supermarkets. (Think of something like a cross-store loyalty card system.) customer(cID, cName, street, city) Customers with unique cID and other attributes store(sID, sName, street, city) Stores with a unique ID and other attributes. Stores with the same name...

  • Hello. I am using a Java program, which is console-baed. Here is my question. Thank you....

    Hello. I am using a Java program, which is console-baed. Here is my question. Thank you. 1-1 Write a Java program, using appropriate methods and parameter passing, that obtains from the user the following items: a person’s age, the person’s gender (male or female), the person’s email address, and the person’s annual salary. The program should continue obtaining these details for as many people as the user wishes. As the data is obtained from the user validate the age to...

  • In this project you will create a console C++ program that will have the user to...

    In this project you will create a console C++ program that will have the user to enter Celsius temperature readings for anywhere between 1 and 365 days and store them in a dynamically allocated array, then display a report showing both the Celsius and Fahrenheit temperatures for each day entered. This program will require the use of pointers and dynamic memory allocation. Getting and Storing User Input: For this you will ask the user how many days’ worth of temperature...

  • write a code (perference C or C++) to create a program for a medical doctor must...

    write a code (perference C or C++) to create a program for a medical doctor must be able to book appoint persons first and last name, doctor they wish to say, date and time they wish to see the doctor must be able to add, edit and delete doctors and their information like their field of medicine must be able to add, edit and delete patients following information first name middle name last name date of birth (dd/mm/yyyy) age blood...

  • A database used for a toy store that keeps track of the inventory and purchase orders...

    A database used for a toy store that keeps track of the inventory and purchase orders from the store. All clients will have their membership ID card to shop. This database will help the store to keep track of their orders. It will also help the store to know how many products are available in the inventory. It is necessary to have a membership to purchase a product. The customer can also bring coupons to get discount. Key attributes: Salesman:...

  • A database used for a toy store that keeps track of the inventory and purchase orders...

    A database used for a toy store that keeps track of the inventory and purchase orders from the store. All clients will have their membership ID card to shop. This database will help the store to keep track of their orders. It will also help the store to know how many products are available in the inventory. It is necessary to have a membership to purchase a product. The customer can also bring coupons to get discount. Key attributes: Salesman:...

  • Assignment: Write a program in C++ that allows a customer to go on-line shopping. This is...

    Assignment: Write a program in C++ that allows a customer to go on-line shopping. This is a start-up venture and the stock of our on-line company is currently limited to the following items: A gift card to Home Depot, $50.00 A bottle of cologne (The One by Dolce Gabbana), $24.00 3. Akeychainwithabathtubornament,$14.00 4. Acard,$4.00 Although all items are in stock, the customer should only be made aware of the items that he or she can afford. In addition, demand for...

  • C++ requirements The store number must be of type unsigned int. The sales value must be...

    C++ requirements The store number must be of type unsigned int. The sales value must be of of type long long int. Your program must properly check for end of file. See the section Reading in files below and also see your Gaddis text book for details on reading in file and checking for end of file. Your program must properly open and close all files. Failure to follow the C++ requirements could reduce the points received from passing the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT