Hi,
The program compiles and executes with no errors but its not saving the category that the users enters as one of the constants listed in the enum 'ItemCategory'. So if the users types 1, it should save category as 'Women', if users types 5, the program should save category as 'Babies' etc. Category is displayed as blank but everything else is shown correctly.
I haven't done the data validation yet, I will do that later.
So if you guys can please help me out, I'd appreciate it, thank you.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DepartmentStore9
{
public enum ItemCategory
{
Unspecified,
Women,
Girls,
Men,
Boys,
Babies
}
class ShoppingItem
{
private ItemCategory cat;
private long itemNo;
private string name;
private string size;
private decimal price;
//private uint category = 1;
// A constructor used to initialize an item
/* Custom constructor
*/
public ShoppingItem(long itemNo,
string name,
string size,
decimal price)
{
this.itemNo = itemNo;
this.name = name;
this.size = size;
this.price = price;
}
public ShoppingItem() // default constructor
{
}
// A property for the stock number of an item
public long ItemNumber
{
get
{
return this.itemNo;
}
set
{
this.itemNo = value;
}
}
// A property for the name of an item
public string Name
{
get
{
return this.name;
}
set
{
this.name = value;
}
}
// A property for size of a merchandise
public string Size
{
get
{
if (this.size == "0")
return "Unknown Size or Fits All";
else
return this.size;
}
set
{
this.size = value;
}
}
// A property for the marked price of an item
public decimal UnitPrice
{
get
{
return this.price;
}
set
{
this.price = value;
}
}
public ItemCategory Category
{
get
{
return cat;
}
set
{
cat = value;
}
}
public static ShoppingItem Read()
{
ShoppingItem store = new ShoppingItem();
int category;
Console.WriteLine("Department Store");
Console.Write("Enter number#: ");
store.ItemNumber = long.Parse(Console.ReadLine());
Console.WriteLine("Store Items category");
Console.WriteLine("\t1. Women");
Console.WriteLine("\t2. Girls");
Console.WriteLine("\t3. Men");
Console.WriteLine("\t4. Boys");
Console.WriteLine("\t5. Babies");
Console.Write("Enter the category \t");
category = int.Parse(Console.ReadLine());
//-------------------------- debug purposes
Console.WriteLine("category entered is: ", category.ToString());
//-----------------------------
if (category == 1)
{
store.Category = ItemCategory.Women;
}
if (category == 2)
{
store.Category = ItemCategory.Girls;
}
if (category == 3)
{
store.Category = ItemCategory.Men;
}
if (category == 4)
{
store.Category = ItemCategory.Boys;
}
if (category == 5)
{
store.Category = ItemCategory.Babies;
}
else
{
store.Category = ItemCategory.Unspecified;
}
//-------------------debug purposes
Console.WriteLine("category saved is: ", store.Category);
//-------------------
Console.Write("Enter name#: ");
store.Name = Console.ReadLine();
Console.Write("Enter size#: ");
store.Size = Console.ReadLine();
Console.Write("Enter price#: ");
store.UnitPrice = decimal.Parse(Console.ReadLine());
return store;
}
public static void write(ShoppingItem store)
{
Console.WriteLine("Department Store invoice");
Console.WriteLine("---------------------------");
Console.WriteLine("Customer Invoice#: ");
Console.WriteLine("---------------------------");
Console.WriteLine("Item #: {0}", store.ItemNumber.ToString());
Console.WriteLine("Category#: ", store.Category);
Console.WriteLine("Description: {0}", store.Name);
Console.WriteLine("Item Size: {0}", store.Size);
Console.WriteLine("Unit Price: {0:C}", store.UnitPrice);
}
}
}