ShirtDemo Console App


Program.cs

[code language=”csharp”] using System;
using System.Collections.Generic;
using static System.Console;

/// <summary>
/// # # # # # # # # #
/// # Mark Hesser #
/// # Feb 14, 18 #
/// # Shirts Demo #
/// # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
/// # Instructions: #
/// # Create an application named ShirtDemo that declares several Shirt objects and includes a display #
/// # method to which you can pass different numbers of Shirt objects in successive method calls. #
/// # The Shirt class contains auto-implemented properties for a material, color, and size. #
/// # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
/// </summary>
namespace ShirtDemo
{
class Program
{
static void Main(string[] args)
{
Title = "Shirts Demo";

#region Declarations
//bool quit = false;
var shirts = new List<Object>();

//Declare Shirts and add them to the available shirt list.
var s1 = new Shirts("silk", "yellow", "s"); shirts.Add(s1);
var s2 = new Shirts("Cotton", "RED", "XL"); shirts.Add(s2);
var s3 = new Shirts("LINEN", "pink", "L"); shirts.Add(s3);
var s4 = new Shirts("wool", "navy", "4XL"); shirts.Add(s4);
var s5 = new Shirts("silk", "green", "m"); shirts.Add(s5);
var s6 = new Shirts("polyester", "tangerine", "XXL"); shirts.Add(s6);
var s7 = new Shirts("cotton", "purple", "3XL"); shirts.Add(s7);
var s8 = new Shirts("cotton", "orange", "2XL"); shirts.Add(s8);
var s9 = new Shirts(); shirts.Add(s9); //Exmaple of no argument constructor.
#endregion

WriteLine(" * indicates the option selected is not availble.\n");
WriteLine(" Material Color Size Status");

Display(shirts);

Quit();
}

static void Display(List<object> shirts)
{
foreach (var item in shirts)
{
WriteLine(item);
}
}

/// <summary>
/// Prompts the User to Press any Key to Quit.
/// </summary>
static void Quit()
{
Write("\n Press Any Key to Quit."); //Put message to the user here.
ReadKey(); //Listens for Key
}
}
}
[/code]

Shirt.cs

[code language=”csharp”] using System;

/// <summary>
/// # # # # # # # # #
/// # Mark Hesser #
/// # Feb 14, 18 #
/// # Shirt Demo #
/// # # # # # # # # #
/// </summary>
namespace ShirtDemo
{
class Shirts
{
/// <summary>
/// No Argument Constructor Method.
/// </summary>
public Shirts() : this("unknown", "", "")
{

}

/// <summary>
/// Shirts Constructor Method.
/// </summary>
/// <param name="material"></param>
/// <param name="color"></param>
/// <param name="size"></param>
public Shirts(string material, string color, string size, bool status = false)
{
//Available Options for Materials, Colors, and Sizes. If an entry is invalid, N/A is returned.
string[] validMaterials = { "cotton", "polyester", "linen", "silk" };
string[] validColors = { "red", "orange", "yellow", "green", "blue", "navy", "violet", "pink", "black", "gray", "white" };
string[] validSizes = { "XS", "S", "M", "L", "XL", "2XL", "3XL" };
bool isValidMaterial = true;
bool isValidColor = true;
bool isValidSize = true;

//Checks to see if the material referenced is valid.
for (int i = 0; i < validMaterials.Length; i++)
{
Material = material;
if (Material == validMaterials[i])
{
Material = validMaterials[i];
isValidMaterial = true;
break;
}
else
{
isValidMaterial = false;
Material = "*" + material;
}
}

//Checks to see if the color referenced is valid.
for (int i = 0; i < validColors.Length; i++)
{
Color = color;
if (Color == validColors[i])
{
Color = validColors[i];
isValidColor = true;
break;
}
else
{
isValidColor = false;
Color = "*" + color;
}
}

//Checks to see if the size referenced is valid.
for (int i = 0; i < validSizes.Length; i++)
{
Size = size;
if (Size == validSizes[i])
{
Size = validSizes[i];
isValidSize = true;
break;
}
else //marks
{
isValidSize = false;
Size = "*" + size;
}
}

//if all 3 options are valid, status is true (Available)
if (isValidMaterial == true && isValidColor == true && isValidSize == true)
Status = true;
else
Status = false;
}

private string material;
public string Material
{
get { return material.ToLower(); }
set { material = value; }
}

private string color;
public string Color
{
get { return color.ToLower(); }
set { color = value; }
}

private string size;
public string Size
{
get { return size.ToUpper(); }
set { size = value; }
}

public bool Status;

public override string ToString()
{
if (Status == true)
return String.Format(" {0,-12} {1,-12} {2,-8} Available", Material, Color, Size);
else if (Status == false)
return String.Format(" {0,-12} {1,-12} {2,-8} Not Available", Material, Color, Size);
else return " An Error has occured…";

}
}
}
[/code]