Question

--USING C# ONLY-- You will create your own on-line shopping store in the console application. You...

--USING C# ONLY-- 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 allow the 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 spends each time to determine the discount level. You can create your discount level rule or use the rule in the assignment 4. The program has to keep tracking the products inventory. If the customer selects the product that is out of stock, the program has to display a warning message and let customer continue to shop. After the customer finishes 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. (Just like a standard store receipt). Manager: The manager option has to be password protected. The program will give the manager two options: 1. Display the inventory: display all the products stock information. 2. Restock the products: add more stock for each product. You have to create different classes and utilize the inheritance features. You have to create text files to keep all the information the program needs. You can check some on-line stores to get some ideas (Amazon, Walmart …). Make sure your program does not end unexpectedly and let user have the option to continue.

Homework Answers

Answer #1

ANSWER :

GIVEN DATA

CODE:

using System;

namespace OnlineShopping
{
class Program
{
static void Main(string[] args)
{
BusinessLogic BL = new BusinessLogic();

int choice;
do
{
Console.WriteLine("Main Menu :: ");
Console.WriteLine("Press <1> for Customer");
Console.WriteLine("Press <2> for Manager");
Console.WriteLine("Press <3> for Exit");
Console.Write("Choice : ");
choice = (int)BusinessLogic.AcceptUntilValidInput(Console.ReadLine(), "Choice");
if (choice == 1)
{
BL.ProcessCustomer();
}
else if (choice == 2)
{
BL.ProcessManager();
}
else if (choice == 3)
{
break;
}
else
{
Console.WriteLine("Error :: Invalid Choice!");
}
Console.WriteLine("");
} while (choice != 3);
}
}
}

-------------------- Receipt.cs --------------------

using System;
using System.Collections.Generic;

namespace OnlineShopping
{
class Receipt
{
public int OrderNumber { get; set; } = 1234;
public DateTime OrderDate { get; set; }
public Customer Customer { get; set; }
public List<Inventory> Items { get; set; }
public double Subtotal { get; set; }
public double Tax { get; set; }
public double Discount { get; set; }
public double Total { get; set; }

public void ProcessCalculation()
{
for (int i = 0; i < Items.Count; i++)
{
Subtotal += Items[i].Quantity * Items[i].Price;
}
Tax = Subtotal * (Inventory.Tax / 100.0);
if (Customer.DiscountAllotted != 0)
{
Discount = Subtotal * (Customer.DiscountAllotted / 100.0);
}
Total = (Subtotal + Tax) - Discount;
this.Customer.TotalSpend += Total;
}
}
}

-------------------- Manager.cs --------------------

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

namespace OnlineShopping
{
class Manager
{
public string Name { get; set; }
public string Password { get; private set; } = "password123";
public bool IsManagerAuthorised()
{
Console.Write("Enter manager password : ");
string password = Console.ReadLine();
if (Password == password)
{
return true;
}
return false;
}

public static void ShowStockInformation(List<Inventory> Items)
{
if (Items.Count > 0)
{
string header = "Code".PadRight(6) + "Name".PadRight(20) + "Quantity".PadRight(10) + "Price";
Console.WriteLine(header);
Console.WriteLine("".PadRight(44, '-'));
for (int i = 0; i < Items.Count; i++)
{
Inventory inv = Items[i];
string code = inv.ItemNumber.ToString().PadRight(6);
string name = inv.Name.PadRight(20);
string quantity = inv.Quantity.ToString().PadLeft(8);
string price = "$".PadLeft(3) + inv.Price.ToString("0.00");
string line = code + name + quantity + price;
Console.WriteLine(line);
}
}
else
{
Console.WriteLine("Error :: No items in the inventory!");
}
}

public List<Inventory> Restock(List<Inventory> Items)
{
if (Items.Count > 0)
{
int choice;
do
{
Console.WriteLine("\nSub Menu :: ");
Console.WriteLine("Press <1> for new inventory item");
Console.WriteLine("Press <2> for existing inventory item");
Console.WriteLine("Press <3> Goto Main menu");
Console.Write("Enter your choice : ");
choice = (int)BusinessLogic.AcceptUntilValidInput(Console.ReadLine(), "Choice");
if (choice == 1)
{
Inventory inv = new Inventory();
Console.Write("Enter item number : ");
inv.ItemNumber = (int)BusinessLogic.AcceptUntilValidInput(Console.ReadLine(), "item number");
Console.Write("Enter item name : ");
inv.Name = Console.ReadLine();
Console.Write("Enter item price : $");
inv.Price = BusinessLogic.AcceptUntilValidInput(Console.ReadLine(), "item price");
Console.Write("Enter item quantity : ");
inv.Quantity = (int)BusinessLogic.AcceptUntilValidInput(Console.ReadLine(), "item quantity");
Items.Add(inv);
Console.WriteLine("Item updated successfully!");
}
else if (choice == 2)
{

Console.Write("Enter item number :");
int itemNumber = (int)BusinessLogic.AcceptUntilValidInput(Console.ReadLine(), "item number");
var item = Items.Find(x => x.ItemNumber == itemNumber);
if (item != null)
{
Console.Write("Enter item quantity : ");
int Quantity = (int)BusinessLogic.AcceptUntilValidInput(Console.ReadLine(), "item quantity");
Items.Find(x => x.ItemNumber == item.ItemNumber).Quantity += Quantity;
Console.WriteLine("Item updated successfully!");
}
else
{
Console.WriteLine("Error :: Item doesn't exist!");
}
}
else if (choice == 3)
{
break;
}
else
{
Console.WriteLine("Error :: Invalid choice!");
}
} while (choice != 3);
}
return Items;
}
}
}

-------------------- Inventory.cs --------------------

namespace OnlineShopping
{
class Inventory
{
public const int Tax = 8;
public int ItemNumber { get; set; }
public string Name { get; set; }
public int Quantity { get; set; }
public double Price { get; set; }
}
}

-------------------- Customer.cs --------------------

using System;
using System.IO;

namespace OnlineShopping
{
class Customer
{
public int Id { get; set; } = 999;
public string Name { get; set; }
public string Address { get; set; }
public double TotalSpend { get; set; }
public int DiscountAllotted { get; set; } = 0;
public bool IsCustomerExist(int Id)
{
string filePath = BusinessLogic.FilenameCustomer;
if (File.Exists(filePath) && File.ReadAllLines(filePath).Length > 0)
{
string[] lines = File.ReadAllLines(filePath);
for (int i = 0; i < lines.Length; i++)
{
string[] line = lines[i].Split('\t');
int custId = Convert.ToInt32(line[0]);
if (custId == Id)
{
this.Id = custId;
this.Name = line[1];
this.Address = line[2];
this.DiscountAllotted = Convert.ToInt32(line[3]);
this.TotalSpend = Convert.ToDouble(line[4]);
return true;
}
}

}
else
{
File.WriteAllText(filePath, "");
}
return false;
}

public Customer EnterNewCustomerDetails()
{
string filepath = BusinessLogic.FilenameCustomer;
if (File.Exists(filepath) && File.ReadAllLines(filepath).Length > 0)
{
string[] lines = File.ReadAllLines(filepath);
string lastLine = lines[lines.Length-1];
string customerId = lastLine.Split('\t')[0];
Id = Convert.ToInt32(customerId) + 1;
}
else
Id++;

Console.Write("Please enter your name : ");
Name = Console.ReadLine();

Console.Write("Please enter your address : ");
Address = Console.ReadLine();

TotalSpend = DiscountAllotted = 0;
Console.WriteLine("Customer details successfully added!");
Console.WriteLine("Your Customer id is " + Id);
return this;
}

public int ProcessDiscountAlloted()
{
if (this.TotalSpend >= 2000)
this.DiscountAllotted = 10;
else if (this.TotalSpend >= 1500)
this.DiscountAllotted = 8;
else if (this.TotalSpend >= 1000)
this.DiscountAllotted = 6;
else if (this.TotalSpend >= 500)
this.DiscountAllotted = 5;
else
this.DiscountAllotted = 0;

return this.DiscountAllotted;
}
}
}

-------------------- BusinessLogic.cs --------------------

using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;

namespace OnlineShopping
{
class BusinessLogic
{
public static string baseDirectory,
FilenameInventory,
FilenameCustomer,
FilenameOrder;
public BusinessLogic()
{
baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
FilenameInventory = Path.Combine(baseDirectory, "Inventory Details", "ProductInventory.txt");
FilenameCustomer = Path.Combine(baseDirectory, "Customer Details", "Customers.txt");
FilenameOrder = Path.Combine(baseDirectory, "Order Details");

if (!Directory.Exists(Path.GetDirectoryName(FilenameInventory)))
Directory.CreateDirectory(Path.GetDirectoryName(FilenameInventory));

if (!Directory.Exists(Path.GetDirectoryName(FilenameCustomer)))
Directory.CreateDirectory(Path.GetDirectoryName(FilenameCustomer));

if (!Directory.Exists(FilenameOrder))
Directory.CreateDirectory(FilenameOrder);


ReadFromFileInventory();
ReadFromFileCustomer();
}
public List<Inventory> Items { get; set; }
public List<Customer> Customers { get; set; }
public static double AcceptUntilValidInput(string input, string name)
{
double value;
while (true)
{
if (double.TryParse(input, out value))
{
return value;
}
else
{
Console.WriteLine("Error :: Invalid {0}, Try again!", name);
Console.Write("Enter {0} again : ", name);
input = Console.ReadLine();
}
}
}
public void ReadFromFileCustomer()
{
Customers = new List<Customer>();
if (File.Exists(FilenameCustomer))
{
string[] lines = File.ReadAllLines(FilenameCustomer);
for (int i = 0; i < lines.Length; i++)
{
string[] line = lines[i].Split('\t');
Customer cust = new Customer()
{
Id = Convert.ToInt32(line[0]),
Name = line[1],
Address = line[2],
DiscountAllotted = Convert.ToInt32(line[3]),
TotalSpend = Convert.ToDouble(line[4])
};

Customers.Add(cust);
}
}
else
File.WriteAllText(FilenameCustomer, "");
}

public void ReadFromFileInventory()
{
if (File.Exists(FilenameInventory))
{
Items = new List<Inventory>();
string[] lines = File.ReadAllLines(FilenameInventory);
for (int i = 0; i < lines.Length; i++)
{
string[] line = lines[i].Split('\t');
Inventory inv = new Inventory();
inv.ItemNumber = Convert.ToInt32(line[0]);
inv.Name = line[1];
inv.Quantity = Convert.ToInt32(line[2]);
inv.Price = Convert.ToDouble(line[3]);
Items.Add(inv);
}
}
else
{
Console.WriteLine("Error :: File doesn't exist!");
}
}

public void WriteToFileInventory()
{
if (!File.Exists(FilenameInventory))
{
File.WriteAllText(FilenameInventory, "");
}

string[] lines = new string[Items.Count];
for (int i = 0; i < Items.Count; i++)
{
Inventory inv = Items[i];
string line = inv.ItemNumber + "\t" + inv.Name + "\t" + inv.Quantity + "\t" + inv.Price.ToString("0.00");
lines[i] = line;
}
File.WriteAllLines(FilenameInventory, lines);
}

public void WriteToFileReceipt(Receipt receipt)
{
string filePath = "";
DirectoryInfo d = new DirectoryInfo(FilenameOrder);
FileInfo[] Files = d.GetFiles("*.txt");
FileInfo FI = Files.OrderBy(x => x.Name).FirstOrDefault(x => x.Name != "");
if (FI != null)
{
receipt.OrderNumber = Convert.ToInt32(FI.Name.Split(' ')[1]);
receipt.OrderNumber++;
}

filePath = Path.Combine(FilenameOrder, "Order_ID " + receipt.OrderNumber + " For Customer_ID " + receipt.Customer.Id + ".txt");

var lines = new List<string>();
lines.Add("Receipt :: ");
lines.Add("[ABC Company]");
lines.Add("[Address]");
lines.Add("[Phone Number]");
lines.Add("Order ID : " + receipt.OrderNumber);
lines.Add("Order Date : " + receipt.OrderDate.ToString());
lines.Add("Customer ID : " + receipt.Customer.Id);
lines.Add("Customer Name : " + receipt.Customer.Name);
string header = "Name".PadRight(20) + "Quantity".PadRight(10) + "Price($)".PadLeft(12);
lines.Add(header);
lines.Add("".PadRight(40, '-'));
for (int i = 0; i < receipt.Items.Count; i++)
{
Inventory inv = receipt.Items[i];
string line = inv.Name.PadRight(20) + inv.Quantity.ToString().PadLeft(8) + ToCurrencyString(inv.Price).PadLeft(14);
lines.Add(line);
}
lines.Add("");
lines.Add("Subtotal : " + ToCurrencyString(receipt.Subtotal));
lines.Add("Tax : " + ToCurrencyString(receipt.Tax));
string discountPercentage = "Discount (" + receipt.Customer.DiscountAllotted + "%)".PadRight(15) + ":";
lines.Add(discountPercentage + ToCurrencyString(receipt.Discount));
lines.Add("".PadRight(20, '-'));
lines.Add("Total : " + ToCurrencyString(receipt.Total));
lines.Add("".PadRight(20, '-'));
lines.Add("Grand Total Spend : " + ToCurrencyString(receipt.Customer.TotalSpend));
lines.Add("Future Discount Alloted : " + receipt.Customer.ProcessDiscountAlloted() + "%");
File.WriteAllLines(filePath, lines);
Console.WriteLine("Successfully updated receipt file on location : " + filePath);
Console.WriteLine(string.Join("\n", lines));
}

public void WriteToFileCustomer(Customer c1)
{
if (File.Exists(FilenameCustomer))
{
List<string> lines = new List<string>();

if (Customers.Count == 0)
{
c1.ProcessDiscountAlloted();
lines.Add(c1.Id + "\t" + c1.Name + "\t" + c1.Address + "\t" + c1.DiscountAllotted + "\t" + c1.TotalSpend);
}
else
{
bool IsCustomerExist = false;
for (int i = 0; i < Customers.Count; i++)
{
Customer customer = Customers[i];
if (customer.Id == c1.Id)
{
customer = c1;
IsCustomerExist = true;
}
customer.ProcessDiscountAlloted();
lines.Add(customer.Id + "\t" + customer.Name + "\t" + customer.Address + "\t" + customer.DiscountAllotted + "\t" + customer.TotalSpend);
}
if (IsCustomerExist == false)
{
c1.ProcessDiscountAlloted();
lines.Add(c1.Id + "\t" + c1.Name + "\t" + c1.Address + "\t" + c1.DiscountAllotted + "\t" + c1.TotalSpend);
}
}

File.WriteAllLines(FilenameCustomer, lines);
Console.WriteLine("Successfully updated customers file on location : " + FilenameCustomer);
}
else
{
File.WriteAllText(FilenameCustomer, "");
}
}

private Inventory IsCodeExist(int code)
{
Inventory inv = null;
for (int i = 0; i < Items.Count; i++)
{
if (Items[i].ItemNumber == code)
{
inv = Items[i];
break;
}
}
return inv;
}

public List<Inventory> ChooseItem()
{
int code = 0;
List<Inventory> OrderedItems = new List<Inventory>();
do
{
Console.Write("Please enter the code to pick item (0 for submit and print receipt) : ");
code = (int)AcceptUntilValidInput(Console.ReadLine(), "code");
if (code == 0)
break;
Inventory inventory;
Inventory item = IsCodeExist(code);
if (item != null)
{
if (item.Quantity > 0)
{
do
{
Console.Write("Enter how many quantity required : ");
int quantity = (int)AcceptUntilValidInput(Console.ReadLine(), "quantity");
if (quantity == 0)
{
Console.WriteLine("Error :: Enter quantity greater than zero!");
}
else if (item.Quantity >= quantity)
{
Items.Find(x => x.ItemNumber == item.ItemNumber).Quantity -= quantity;
inventory = new Inventory()
{
ItemNumber = item.ItemNumber,
Name = item.Name,
Price = item.Price,
Quantity = quantity
};
break;
}
else
{
Console.WriteLine("Error :: Insufficient quantity in store!");
}
} while (true);
OrderedItems.Add(inventory);
}
else
{
Console.WriteLine("Error :: Insufficient quantity!");
}
}
else
{
Console.WriteLine("Error :: Code doesn't exist!");
}
} while (code != 0);

return OrderedItems;
}

public void ProcessCustomer()
{
Customer customer = new Customer();
Console.Write("Are you a new customer? (y/n) : ");
char option = Console.ReadLine()[0];
if (option == 'n')
{
Console.Write("Enter your customer id : ");
int id = (int)AcceptUntilValidInput(Console.ReadLine(), "custumer id");
bool IsExist = customer.IsCustomerExist(id);
if (IsExist)
{
Console.WriteLine("Customer Name : " + customer.Name);
Console.WriteLine("Customer Address : " + customer.Address);
Console.WriteLine("Customer Total Spend : " + ToCurrencyString(customer.TotalSpend));
Console.WriteLine("Customer Discount Alloted : " + customer.DiscountAllotted);
Manager.ShowStockInformation(Items);
var orderedItems = ChooseItem();
if (orderedItems.Count > 0)
{
Receipt receipt = new Receipt();
receipt.OrderNumber++;
receipt.OrderDate = DateTime.Now;
receipt.Customer = customer;
receipt.Items = orderedItems;
receipt.ProcessCalculation();
WriteToFileReceipt(receipt);
WriteToFileCustomer(receipt.Customer);
WriteToFileInventory();
}
}
else
{
Console.WriteLine("Error :: Customer doesn't exist!");
}
}
else if (option == 'y')
{
Customer cust = customer.EnterNewCustomerDetails();
WriteToFileCustomer(cust);
ProcessCustomer();
}
else
{
Console.WriteLine("Error :: Invalid option!");
}
}

public void ProcessManager()
{
Manager manager = new Manager();
if (manager.IsManagerAuthorised())
{
int choice;
do
{
Console.WriteLine("\nSub Menu :: ");
Console.WriteLine("Press <1> to Display all the products stock information");
Console.WriteLine("Press <2> to Add more stock for each product");
Console.WriteLine("Press <3> Goto Main Menu");
Console.Write("Enter your choice : ");
choice = (int)AcceptUntilValidInput(Console.ReadLine(), "choice");
if (choice == 1)
{
Manager.ShowStockInformation(Items);
}
else if (choice == 2)
{
Items = manager.Restock(Items);
WriteToFileInventory();
}
else if (choice == 3)
{
break;
}
else
{
Console.WriteLine("Error :: Invalid Choice");
}
} while (true);
}
else
{
Console.WriteLine("Error :: Incorrect Password!");
}
}

public string ToCurrencyString(double value)
{
return value.ToString("C", CultureInfo.CreateSpecificCulture("en-US"));
}
}
}

SCREEN SHOTS :

Know the answer?
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
Similar Questions
I am looking for PYTHON code that will display the following: Code a menu-driven application that...
I am looking for PYTHON code that will display the following: Code a menu-driven application that does the following: The user can enter data for a product name, product code, and unit price. An example might be 'Breaburn Apples', 'BAP'. 1.99. After entering the data, it is appended (note I said 'appended') as a single line of text to a text file. Each line of text in the file should represent a single product. There is an option to display...
PYTHON Driver’s License The local driver’s license office has asked you to create an application that...
PYTHON Driver’s License The local driver’s license office has asked you to create an application that grades the written portion of the driver’s license. The paper has 20 multiple-choice questions. Here are the correct answers: A C A A D B C A C B A D C A D C B B D A Your program should store these correct answers in a list. The program should read the student’s answers for each of the 20 questions from a...
**[70 pts]** You will be writing a (rather primitive) online store simulator. It will have these...
**[70 pts]** You will be writing a (rather primitive) online store simulator. It will have these classes: Product, Customer, and Store. All data members of each class should be marked as **private** (a leading underscore in the name). Since they're private, if you need to access them from outside the class, you should do so via get or set methods. Any get or set methods should be named per the usual convention ("get_" or "set_" followed by the name of...
C# Programming Using the Example provided in this Week Folder,Create a Console application that solve the...
C# Programming Using the Example provided in this Week Folder,Create a Console application that solve the following problem: The heating system in a school should be switched on if the average temperature is less than 17 degrees Celsius. The average temperature is found from the temperatures in the Math, English and IT departments. You are required to write a program that allows the user to input 3 temperatures. The program calculates and displays the average temperature and then displays "heating...
This program is in C++: Write a program to allow the user to: 1. Create two...
This program is in C++: Write a program to allow the user to: 1. Create two classes. Employee and Departments. The Department class will have: DepartmentID, Departmentname, DepartmentHeadName. The Employee class will have employeeID, emploeename, employeesalary, employeeage, employeeDepartmentID. Both of the above classes should have appropriate constructors, accessor methods. 2. Create two arrays . One for Employee with the size 5 and another one for Department with the size 3. Your program should display a menu for the user to...
C++ Visual Studio 2019 Write a C++ console application that accepts up to 5 numbers from...
C++ Visual Studio 2019 Write a C++ console application that accepts up to 5 numbers from the user. Display all numbers, the highest, the lowest, and the average of the numbers. Ask the user if they want to continue entering another set of numbers. 1) Use proper naming conventions for your variables and functions. 2) Tell the user what the program is all about. Do NOT start the program with “Enter a number”!! 3) Create an array to store the...
Please use C++. You will be provided with two files. The first file (accounts.txt) will contain...
Please use C++. You will be provided with two files. The first file (accounts.txt) will contain account numbers (10 digits) along with the account type (L:Loan and S:Savings) and their current balance. The second file (transactions.txt) will contain transactions on the accounts. It will specifically include the account number, an indication if it is a withdrawal/deposit and an amount. Both files will be pipe delimited (|) and their format will be the following: accounts.txt : File with bank account info...
In the previous assessment, you used a static set of named variables to store the data...
In the previous assessment, you used a static set of named variables to store the data that was entered in a form to be output in a message. For this assessment, you will use the invitation.html file that you modified in the previous assessment to create a more effective process for entering information and creating invitations for volunteers. Rather than having to enter each volunteer and create an invitation one at a time, you will create a script that will...
Hello, can you teach me how to draw a Use Case diagram for this given scenario?...
Hello, can you teach me how to draw a Use Case diagram for this given scenario? I also need to include all the extends and includes relationships. Case Description Acme Drug Stores (ADS) which consists of a chain of retail stores across Canada wants to be able to provide a new online customer service system. Each store has an identifying store no, address, phone, and email. The company dispenses a wide range of pharmaceutical (drug) products. Each product has a...
Please create your own Excel file to conduct scenario analysis illustrated below: Suppose you have been...
Please create your own Excel file to conduct scenario analysis illustrated below: Suppose you have been hired as a financial consultant to Cape Cod Fishing, Inc. (CCF), a large firm that is the market share leader in manufacturing fishing products. The company is looking at setting up a manufacturing plant to produce a new line of fishing bait, which specially formulated for attracting bluefin tuna. To illustrate, suppose the company can sell 87,300 cans of bait per year at a...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT