In: Computer Science
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 (all of type string).
Here is my code:
//Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ShirtApplication
{
class Program
{
static void Main(string[] args)
{
//Create an instance of Shirt
Shirt shirt = new Shirt("cotton", "white", "L");
//print heading
Console.WriteLine("{0,-12}{1,10}{2,10}", "Material", "Color","Size");
//call display method
display(shirt);
//Create an instance of Shirt
shirt = new Shirt("cotton", "blue", "XL");
//call display method
display(shirt);
//Create an instance of Shirt
shirt = new Shirt("polyester", "pink", "M");
//call display method
display(shirt);
Console.WriteLine();
Console.WriteLine("{0,-12}{1,10}{2,10}", "Material", "Color", "Size");
//Create an instance of Shirt
shirt = new Shirt("cotton", "white", "L");
//call display method
display(shirt);
//Create an instance of Shirt
shirt = new Shirt("cotton", "blue", "XL");
//call display method
display(shirt);
//Create an instance of Shirt
shirt = new Shirt("polyester", "pink", "M");
//call display method
display(shirt);
//Create an instance of Shirt
shirt = new Shirt("silk", "yellow", "S");
//call display method
display(shirt);
Console.WriteLine();
Console.WriteLine("{0,-12}{1,10}{2,10}", "Material", "Color", "Size");
//Create an instance of Shirt
shirt = new Shirt("cotton", "white", "L");
//call display method
display(shirt);
//Create an instance of Shirt
shirt = new Shirt("cotton", "blue", "XL");
//call display method
display(shirt);
shirt = new Shirt("polyester", "pink", "M");
//call display method
display(shirt);
//Create an instance of Shirt
shirt = new Shirt("silk", "yellow", "S");
display(shirt);
shirt = new Shirt("silk", "white", "XXL");
//call display method
display(shirt);
Console.ReadKey();
}
//The metod display that takes Shirt object and prints the properties of shirt object
//to console
public static void display(Shirt shirt)
{
Console.WriteLine("{0,12}{1,10}{2,10}", shirt.Material, shirt.Color, shirt.Size);
}
}
}
here is the error message:
Unable to instantiate shirt objects with the correct properties.
Checks
Unit TestIncomplete
Shirt class is defined and can be instantiated
Build Status
Build Failed
Build Output
Compilation failed: 1 error(s), 0 warnings ShirtDemo.cs(77,36): error CS0246: The type or namespace name `Shirt' could not be found. Are you missing an assembly reference?
Test Contents
[TestFixture]
public class ShirtClassTest
{
[Test]
public void Shirt()
{
Shirt shirt1 = new Shirt();
shirt1.Material = "cotton";
shirt1.Color = "Green";
shirt1.Size = "Large";
Shirt shirt2 = new Shirt();
shirt2.Material = "polyester";
shirt2.Color = "red";
shirt2.Size = "small";
Assert.AreEqual("cotton", shirt1.Material);
Assert.AreEqual("Green", shirt1.Color);
Assert.AreEqual("Large", shirt1.Size);
Assert.AreEqual("polyester", shirt2.Material);
Assert.AreEqual("red", shirt2.Color);
Assert.AreEqual("small", shirt2.Size);
}
}
Unit TestIncomplete
Get and set the Material property of the Shirt object, test 1
Build Status
Build Failed
Build Output
Compilation failed: 1 error(s), 0 warnings ShirtDemo.cs(77,36): error CS0246: The type or namespace name `Shirt' could not be found. Are you missing an assembly reference?
Test Contents
[TestFixture]
public class ShirtClassTest
{
[Test]
public void Shirt()
{
Shirt shirt1 = new Shirt();
shirt1.Material = "cotton";
Shirt shirt2 = new Shirt();
shirt2.Material = "polyester";
Assert.AreEqual("cotton", shirt1.Material, "Unable to set or get the `Material` property of the class `Shirt`");
Assert.AreEqual("polyester", shirt2.Material, "Unable to set or get the `Material` property of the class `Shirt`");
}
}
Unit TestIncomplete
Get and set the Color property of the Shirt class, test 2
Build Status
Build Failed
Build Output
Compilation failed: 1 error(s), 0 warnings ShirtDemo.cs(77,36): error CS0246: The type or namespace name `Shirt' could not be found. Are you missing an assembly reference?
Test Contents
[TestFixture]
public class ShirtClassTest
{
[Test]
public void Shirt()
{
Shirt shirt1 = new Shirt();
shirt1.Color = "Green";
Shirt shirt2 = new Shirt();
shirt2.Color = "red";
Assert.AreEqual("Green", shirt1.Color, "Unable to set or get the `Color` property of the class `Shirt`");
Assert.AreEqual("red", shirt2.Color, "Unable to set or get the `Color` property of the class `Shirt`");
}
}
Unit TestIncomplete
Get and set the Size property of the Shirt class, test 3
Build Status
Build Failed
Build Output
Compilation failed: 1 error(s), 0 warnings ShirtDemo.cs(77,36): error CS0246: The type or namespace name `Shirt' could not be found. Are you missing an assembly reference?
Test Contents
[TestFixture]
public class ShirtClassTest
{
[Test]
public void Shirt()
{
Shirt shirt1 = new Shirt();
shirt1.Size = "Large";
Shirt shirt2 = new Shirt();
shirt2.Size = "small";
Assert.AreEqual("Large", shirt1.Size, "Unable to set or get the `Size` property of the class `Shirt`");
Assert.AreEqual("small", shirt2.Size, "Unable to set or get the `Size` property of the class `Shirt`");
}
}
0.00 out of 10.00
Display method defined
2
0 out of 2 checks passed. Review the results below for more details.
Checks
Unit TestIncomplete
Display method displays all shirt properties, test 1
Build Status
Build Failed
Build Output
Compilation failed: 2 error(s), 0 warnings NtTest2202f400.cs(6,14): error CS0246: The type or namespace name `ShirtDemo' could not be found. Are you missing an assembly reference? ShirtDemo.cs(77,36): error CS0246: The type or namespace name `Shirt' could not be found. Are you missing an assembly reference?
Test Contents
[TestFixture]
public class ShirtClassDisplayTest
{
[Test]
public void ShirtTest1()
{
using (StringWriter sw = new StringWriter())
{
Console.SetOut(sw);
Shirt shirt1, shirt2, shirt3;
shirt1 = new Shirt();
shirt2 = new Shirt();
shirt3 = new Shirt();
shirt1.Material = "cotton";
shirt1.Color = "white";
shirt1.Size = "L";
shirt2.Material = "cotton";
shirt2.Color = "blue";
shirt2.Size = "XL";
shirt3.Material = "polyester";
shirt3.Color = "pink";
shirt3.Size = "M";
Display(shirt1, shirt2, shirt3);
StringAssert.Contains("cotton", sw.ToString());
StringAssert.Contains("white", sw.ToString());
StringAssert.Contains("L", sw.ToString());
StringAssert.Contains("blue", sw.ToString());
StringAssert.Contains("XL", sw.ToString());
StringAssert.Contains("polyester", sw.ToString());
StringAssert.Contains("pink", sw.ToString());
StringAssert.Contains("M", sw.ToString());
Assert.IsFalse(sw.ToString().Contains("silk"), "Output should not contain `silk`");
Assert.IsFalse(sw.ToString().Contains("yellow"), "Output should not contain `yellow`");
}
}
}
Unit TestIncomplete
Display method displays all shirt properties, test 2
Build Status
Build Failed
Build Output
Compilation failed: 2 error(s), 0 warnings NtTestfc79b0ec.cs(6,14): error CS0246: The type or namespace name `ShirtDemo' could not be found. Are you missing an assembly reference? ShirtDemo.cs(77,36): error CS0246: The type or namespace name `Shirt' could not be found. Are you missing an assembly reference?
Test Contents
[TestFixture]
public class ShirtClassDisplayTest
{
[Test]
public void ShirtTest2()
{
using (StringWriter sw = new StringWriter())
{
Console.SetOut(sw);
Shirt shirt1, shirt2, shirt3, shirt4;
shirt1 = new Shirt();
shirt2 = new Shirt();
shirt3 = new Shirt();
shirt4 = new Shirt();
shirt1.Material = "cotton";
shirt1.Color = "white";
shirt1.Size = "L";
shirt2.Material = "cotton";
shirt2.Color = "blue";
shirt2.Size = "XL";
shirt3.Material = "polyester";
shirt3.Color = "pink";
shirt3.Size = "M";
shirt4.Material = "silk";
shirt4.Color = "yellow";
shirt4.Size = "S";
Display(shirt1, shirt2, shirt3, shirt4);
StringAssert.Contains("cotton", sw.ToString());
StringAssert.Contains("white", sw.ToString());
StringAssert.Contains("L", sw.ToString());
StringAssert.Contains("blue", sw.ToString());
StringAssert.Contains("XL", sw.ToString());
StringAssert.Contains("polyester", sw.ToString());
StringAssert.Contains("pink", sw.ToString());
StringAssert.Contains("M", sw.ToString());
StringAssert.Contains("silk", sw.ToString());
StringAssert.Contains("yellow", sw.ToString());
StringAssert.Contains("S", sw.ToString());
}
}
}
Code:-
/// Program.cs ///
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ShirtApplication
{
class Program
{
static void
Main(string[] args)
{
Shirt shirt = new Shirt("cotton", "white", "L");
Console.WriteLine("{0,-12}{1,10}{2,10}", "Material",
"Color","Size");
display(shirt);
shirt = new Shirt("cotton", "blue", "XL");
display(shirt);
shirt = new Shirt("polyester", "pink", "M");
display(shirt);
Console.WriteLine();
Console.WriteLine("{0,-12}{1,10}{2,10}", "Material", "Color",
"Size");
shirt = new Shirt("cotton", "white", "L");
display(shirt);
shirt = new Shirt("cotton", "blue", "XL");
display(shirt);
shirt = new Shirt("polyester", "pink", "M");
display(shirt);
shirt = new Shirt("silk", "yellow", "S");
display(shirt);
Console.WriteLine();
Console.WriteLine("{0,-12}{1,10}{2,10}", "Material", "Color",
"Size");
shirt = new Shirt("cotton", "white", "L");
display(shirt);
shirt = new Shirt("cotton", "blue", "XL");
display(shirt);
shirt = new Shirt("polyester", "pink", "M");
display(shirt);
shirt = new Shirt("silk", "yellow", "S");
display(shirt);
shirt = new Shirt("silk", "white", "XXL");
display(shirt);
Console.ReadKey();
}
public static void
display(Shirt shirt)
{
Console.WriteLine("{0,12}{1,10}{2,10}", shirt.Material,
shirt.Color, shirt.Size);
}
}
}
/// Shirt.cs ///
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ShirtApplication
{
class Shirt
{
public string Material {
get; set; }
public string Color {
get; set; }
public string Size {
get; set; }
public Shirt()
{
Material = "";
Color = "";
Size = "";
}
public Shirt(string
material, string color, string size)
{
this.Material = material;
this.Color = color;
this.Size = size;
}
}
}
Code Screenshots:-
Program.cs


Shirt.cs

Output:-

Please UPVOTE thank you...!!!